Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is wrong with this perl regular expression?

Tags:

regex

perl

I'm trying to go through a file, and only print out words without a specific letter, specified in a character class.

 if ( $+ =~ [^Aa] )
{
print $_;
}

But this doesn't work. What am I doing wrong? The above example should give back a list of words without 'a' or 'A' in them, but it doesn't seem to be working.

like image 283
Waffles Avatar asked May 22 '26 00:05

Waffles


1 Answers

The regular expression says "Include a character that is not A or a" not "Includes only characters that are not A or a".

It is also missing delimiters.

$+ =~ /^[^Aa]*$/

or

$+ !~ /[Aa]/
like image 60
Quentin Avatar answered May 24 '26 20:05

Quentin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!