slugger415 has asked for the wisdom of the Perl Monks concerning the following question:
Hello esteemed monks, I am having trouble with a regex match on a string that contains a regex. I've not figured out how to match on it. This string appears in an HTML page:
document.write(this.location.href.replace(/\?resultof.*$/i, ''));
I need to find and replace it with something else, but I can't seem to match all those regex characters as literals. I've tried replacing all the parens, question marks, etc.
$j =~ s/\\/\\\\/g; $j =~ s/\?/\\\?/g; $j =~ s/\$/\\\$/g; $j =~ s/\*/\\\*/g; $j =~ s/[.]/\\./g; $j =~ s/[)]/\\\)/g; $j =~ s/[(]/\\\(/g;
any thoughts from the experts? thanks
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: matching a "regex" expression
by kennethk (Abbot) on Jun 13, 2012 at 17:11 UTC | |
by slugger415 (Monk) on Jun 13, 2012 at 22:16 UTC | |
Re: matching a "regex" expression
by CountZero (Bishop) on Jun 13, 2012 at 17:14 UTC | |
""regex" expression" - another example of "NIC card" or "ATM machine" usage
by parv (Parson) on Jun 14, 2012 at 08:15 UTC |
Back to
Seekers of Perl Wisdom