zhihuali wrote:
> 
> I was wondering if there's a way to specify "not including this phrase" in 
> perl regexp. 
> Like such two strings:
> axbcabcd
> axbcacbd
> 
> If I say "not including the letter a or the letter b" (=~/[^a^b]/) then
> neither of them will be matched. However now I want to say "not including the
> phrase 'ab'", then the string 2 should be matched. But I can't figure out how
> to specify the second condition by regexp. Could anyone help me?

/[^ab]/ will match if the string contains any character other than a or b, so it
will match both of those strings.

you need to negate the whole match, and say

  not $str =~ /[ab]/

or

  $str !~ /[ab]/

and to to the same with a string like you can write

  not $str =~ /ab/

or

  $str !~ /ab/

for instance

  foreach my $str (qw/axbcabcd axbcacbd/) {
    print "$str\n" if $str !~ /ab/;
  }

outputs just

axbcacbd

HTH,

Rob

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


Reply via email to