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
    Thanks Gopal and Prasad. That was of great help.

    Ananda
Re^2: Regex help reqd
by Anonymous Monk on Jun 27, 2005 at 07:11 UTC
    As an aisle, how will "</section>" be tested?
      This will do the trick

      if($string=~ m/<\/section>/) { print "Here :: $& \n"; } else { print "regex failed"; }