in reply to Substitute within a search

You were actually on exactly the right track with your first regex. The simple trick is to assign $1 to another var, modify that var, and then use the modified value as the substiution like this:

$html =~ s/\n/<br>\n/g; # assume this, and then fix <br> in pre block +s with..... $html =~ s{<pre>(.*?)</pre>} { local $_=$1; s/<br>//g; $_ }gse; print $html;

We need the /g of course, the /s to make . match \n if present and the /e to exec the code in the replace block. The last thing evaluated in the replace block is what is used.

cheers

tachyon

Replies are listed 'Best First'.
Re^2: Substitute within a search
by Anonymous Monk on Aug 26, 2004 at 15:58 UTC
    Thanks, that's exactly what I was looking for! With a small modification, of course: It needs either the parens removed from the first regex, and $1 replaced with $@, or the parens moved to surround the whole expression. That caught me out initailly, as the 'pre' tags weren't coming out ;)