in reply to Strange negated character class behavior

What tybalt89 said. This can be clearly seen by capturing and printing the matching substrings of the regex components:

c:\@Work\Perl\monks>perl -wMstrict -le "my $string = 'CME.b/ESM8'; print qq{'$1' '$2'} if $string =~ /^(CME\.b?)([^\/.])/; " 'CME.' 'b'

Update:

... please explain why ...
The regex engine tries its best to make an overall match any which way it can. The  b? match is specified as being optional. The  b? match assertion initially matches the  'b' character in the string, but the subsequent required  [^/.] match then fails for the reason noted in the OP. The regex engine then backtracks and eliminates the optional  b? match. It then has a  'b' character for  [^/.] to match, and the overall match succeeds.

Question: What would have happened if the  b match had not been optional (fairly obvious), or if it had been a  b?+ possessive (available in Perl versions 5.10+) optional match? (Update: Prior to version 5.10, the possessive quantifier modification effect can be achieved by wrapping the expression in a  (?>...) "atomic" grouping, so  (?>b?) would work exactly the same.)


Give a man a fish:  <%-{-{-{-<