Just do something like this
my $string = q/aab"123"bcc abc="123" abc="345" aab"123"bcc/; $string =~ s/(abc="123")/$1 aabbcc/; # or better (doesn't do unnecessary replacing) $string =~ s/(?<=abc="123")/ aabbcc/; __END__ Benchmark: timing 300000 iterations of lookback, normal... lookback: 4 wallclock secs ( 4.32 usr + 0.01 sys = 4.33 CPU) @ 69 +348.13/s (n=300000) normal: 6 wallclock secs ( 6.01 usr + 0.02 sys = 6.03 CPU) @ 49 +759.50/s (n=300000) Rate normal lookback normal 49759/s -- -28% lookback 69348/s 39% --
A suggestion for the next time, post some code (and the error message you get) so that we can see what you have so far ...
Update: AM is right, the positive lookahead was wrong. I replaced it with a lookbehind and now it works. To show the benefit I also included a small benchmark. As is always the case with benchmarks - results vary depending on the length of the text being replaced.
-- Hofmator
In reply to Re: How do I search and replace a string with quotes
by Hofmator
in thread How do I search and replace a string with quotes
by Hammy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |