in reply to another regex Question
If you add a ? after the *, it will make the expression non-greedy. As long as you don't have any nested tables, this will work. In greedy mode (the default), the regex will grab as much as it can into that .*, matching everything from the first correct table tag, through the very last closing table tag.
outputs:my $thispage = q{ <TABLE border=0 cellPadding=2 cellSpacing=0>junk</TABLE> <TABLE border=0 bogusTag="Don't match this">more junk</TABLE> <TABLE border=0 cellPadding=2 cellSpacing=0>most junk</TABLE> }; $thispage=~s/<TABLE border=0 cellPadding=2 cellSpacing=0>.*?<\/TABLE>/ +/g; print $thispage;
There are better answers to this problem, as others have posted, but I think this "fixes" your regex... :-)
Russ
|
|---|