|
|
| laziness, impatience, and hubris | |
| PerlMonks |
regex escaping forward slash in regexby gilemon (Initiate) |
| on Dec 09, 2009 at 16:22 UTC ( #811960=perlquestion: print w/ replies, xml ) | Need Help?? |
|
gilemon has asked for the
wisdom of the Perl Monks concerning the following question:
I'm doing a Perl script to replace 5.2 deprecated PHP functions like split.
I'm hitting a problem when it comes to replace something like split('/',$string) to preg_split('/\//',$string) so far I came with this regex: s/[^_]split\s*?\(\s*?(["'])((?:\\?.)*?)\1/preg_split($1\/$2\/$1/g but this obviously doesn't work if the regex contains the forward slash character. I also tried this: s/[^_]split\s*?\(\s*?(["'])((?:\\?.)*?)\1/preg_split($1\/\Q$2\E\/$1/g which escapes too many things as it escapes every meta characters. Any secret escape sequence code that only escape forward slashes? Any idea?
Back to
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||||