Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Wondering if anyone else if having an issue with perl 5.14 on ubuntu 12.04 when it comes to negating a character class in Perl.

Given the following small snippet

while(<>) {

    print if /[^Dd]an/;

With the following small input


I would expect


to be printed to the terminal instead I get Frank only.

Just wondering if anyone else was having a similar issue and figured out what the problem was. I'm going to search around for a bit and see if I can come up with anything I'll update if I find anything


share|improve this question
print if ! /[Dd]an/; –  JJoao 23 hours ago

1 Answer 1

The regular expression


Does indeed not match Steve. Basically, you're matching all lines with the sequence an, except those preceeding with a D or d. I don't see how you expect it to match Steve.

I think the behaviour is correct. Keep in mind that the negation is only applying to the characters within the [] section.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.