Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

RE: another regex Question

by Russ (Deacon)
on May 24, 2000 at 09:04 UTC ( [id://14499] : note . print w/replies, xml ) Need Help??

in reply to another regex Question

Just a quick response for you...

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.

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;
<TABLE border=0 cellPadding=2 cellSpacing=1>more junk</TABLE>

There are better answers to this problem, as others have posted, but I think this "fixes" your regex... :-)