in reply to regex: something...(!something)...something

Hi, perhaps I haven't understood your question (and hence this solution may be wrong)... this relates to the greedy nature of quantifiers. Please review the code below and let me know in the same syntax:
$x = "<tr><td>1</td><td>2</td><td><font>3</font></td><td>4</td><tr>"; print "$x\n"; $x =~ s/<td>.*(<td>.*?)3(.*?<\/td>).*<\/td/<td>$1a$2<\/td>/; print "$x\n";
gives me:
<tr><td>1</td><td>2</td><td><font>3</font></td><td>4</td><tr> <tr><td><td><font>a</font></td></td><tr>
is this your desired output?

Replies are listed 'Best First'.
Re^2: regex: something...(!something)...something
by aaaone (Initiate) on Jul 18, 2008 at 12:39 UTC
    Sorry, but no, this is not the desired result.. My mistake - I hadn't told the desired result. If you are interested in the solution, please see Olus's posts. Nevertheless, thanks for help!
      Hi, Sorry about that, nonetheless, this code also will do the trick you want :-)
      $x =~ s/<td>.*<td>(.*?)3(.*?)<\/td>.*<\/td>/<td>$13$2<\/td>/;