Hi, I'm studying for my CIW perl exam, I've come across this question in my exam software, but it doesn't make sense, and my solution is different to the solution given.

Here is the question:

The following RE matches what patterns?

Not Mow
Mow at the beginning of a string
Not Cow
Cow at the beginning of a string
Tow at the beginning of a string
Not Tow

The given solution is 'Not Mow,Not Cow,Not Tow', but when I run it, I get all of them as matches... Its the extra [ that I don't understand, can anyone explain whats going on. :rolleyes:

Thanks very much, I am very grateful for your help

11 Years
Discussion Span
Last Post by KevinADC

Not sure where you got that regexp from but it's either a typographical error or just wrong. The first '. When it's inside the character class it means to not match what's in the character class (a negated character class). Maybe it was supposed to be:


in which case it means to match a string that begins with any character followed by 'ow' but not if the character is T or M or C:

my @strings = ('Cows say moo', 'I Mow the grass', 'Tow the line', 'Bow tie', 'Pow wow', '9ow begins with a digit', ' ow begins with a space');

for (@strings) {
   /^[^TMC]ow/ && print "$_\n";


Bow tie
Pow wow
9ow begins with a digit
 ow begins with a space
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.