in reply to Regex help reqd
.* 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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex help reqd
by Ananda (Pilgrim) on Jun 27, 2005 at 07:23 UTC | |
|
Re^2: Regex help reqd
by Anonymous Monk on Jun 27, 2005 at 07:11 UTC | |
by Anonymous Monk on Jun 27, 2005 at 07:20 UTC |