.* leads to greediness. You must use .*? to avoid the greediness, to match minimum.
You can do this in many ways, like gopal suggested, you can use [^>]+ or you can use (.*?)
Go through perlre.
if($string=~ m/<section [^>]+>/) { print "Here :: $& \n"; } else { print "regex failed"; } or if($string=~ m/<section .*?>/) { print "Here :: $& \n"; } else { print "regex failed"; }
But first option is the safer solution.
Prasad
In reply to Re: Regex help reqd
by prasadbabu
in thread Regex help reqd
by Ananda
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |