Octavian Rasnita wrote:
> 
> I wanted to test something like:
> 
> Match only if the string contains somewhere a "ab" in it but it doesn't 
> contain "ab" between < and >.
> 
> For example:
> 
> "zzz <> ttt> ab" - matches
> "z ab <tt> xx" - matches
> "zzz ab <>ab> tt" - doesn't match
> "ab <a x> <ab>" - doesn't match
> 
> I've done it by using 2 regular expressions, but I was searching for a 
> solution for doing using only a single regular expression. Is it possible to
> test the existence of a string and the non-existence of another string using
> a single regular expression?
> 
> I've tried using (?=...) and (?!...) but these 2 expressions can be used only
> if I know where in the string I want a certain string to appear or not to
> appear.

How about this?

Rob


use strict;
use warnings;

while (<DATA>) {
  chomp;
  my $match = /^(?=.*ab)(?!.*<.*ab.*>)/ ? "matches" : "doesn't match";
  print "$_ - $match\n";
}

__END__
zzz <> ttt> ab
z ab <tt> xx
zzz ab <>ab> tt
ab <a x> <ab>

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to