Stripslashes in Perl

Just a quick bit of code for reference – here’s a regex to implement stripslashes (a useful PHP function)in perl.

$string =~ s/\\([^\\])/$1/g;

Update: Slashes have been escaped. Thanks, helpy.

Another update: In trying to be clever, this does way more than it should. This seems to work better:

$string =~ s/\\(\'|\"|\\)/$1/g

3 thoughts on “Stripslashes in Perl

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" cssfile="">