tunesmith has asked for the wisdom of the Perl Monks concerning the following question:
into this:<p> blah blah <blockquote> blah </blockquote> blah <p>
I tried:<p> <b>blah blah</b> <blockquote> <b>blah</b> </blockquote> <b>blah</b> <p>
But that didn't touch the code inside of <blockquote> because the marker had already gone past that tag on the first match.s/(<.*?>)(.*?)(<.*?>)/$1<b>$2</b>$3/g;
I switched to lookahead/lookback:
But that created extra code; a nested blockquote for example.s/(?=(<.*?>)(.*?)(<.*?>))/$1<b>$2</b>$3/g;
(This is all a simplified case of what I'm actually trying to do.) In summary: How do I do search/replace if a pattern matches both the end of one and the beginning of another string to replace? Alternative solutions: What is the best way to either tell the "replace" part to only print out chunks of code it hasn't printed before, OR, how can I add additional search criteria to the "search" part without it becoming part of the replacement? Like, "search for this whole string, but only replace this portion of that string with this other replacement string".
Thanks, tunesmith
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex: How do I use lookahead with search/replace?
by Roger (Parson) on Feb 22, 2004 at 04:18 UTC | |
|
Re: Regex: How do I use lookahead with search/replace?
by graff (Chancellor) on Feb 22, 2004 at 06:26 UTC | |
by tunesmith (Initiate) on Feb 22, 2004 at 07:30 UTC | |
by graff (Chancellor) on Feb 22, 2004 at 08:27 UTC | |
by tunesmith (Initiate) on Feb 22, 2004 at 09:50 UTC | |
|
Re: Regex: How do I use lookahead with search/replace?
by revdiablo (Prior) on Feb 23, 2004 at 01:17 UTC |