in reply to Is there a nicer way to do regex search and replace with literal backslashes?
I think this is what you were going for:
my $needle = 'mo4\dy13\hr19\\'; my $haystack = '\yr2012\mo4\dy13\hr19\min23\sec51'; $haystack =~ s/\Q$needle\E([^3]*3)/${needle}new/; print 'Final $haystack:', $haystack, "\n";
If you look up quotemeta, or perlretut you'll see discussion on the \Q...\E metacharacters and how they simplify escaping of strings.
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Is there a nicer way to do regex search and replace with literal backslashes?
by AnomalousMonk (Archbishop) on Apr 15, 2012 at 01:09 UTC | |
by davido (Cardinal) on Apr 15, 2012 at 01:22 UTC |