in reply to regex matches more than I want

The easiest way is to change your .* to be an appropriate negated character class or to use the ? modifier on the greedy * to make it less greedy.

  1. print  $#{[$lines =~ /aaa[^b]*bbb[^c]*ccc\s*dddd/gsi]} + 1 . "\n";  # or ...
  2. print  $#{[$lines =~ /aaa.*?bbb.*?ccc\s*dddd/gsi]} + 1 . "\n";

See the documentation in perlre and perlrequick and perlretut

Replies are listed 'Best First'.
Re: Re: regex matches more than I want
by Anonymous Monk on Dec 03, 2003 at 06:36 UTC
    Thanks guys for all the help !!!