Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

Dan
Frank
Steve
daniel

I would expect

Frank
Steve

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

Cheers

share|improve this question
add comment

1 Answer

The regular expression

/[^Dd]an/

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
add comment

Your Answer

 
discard

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.