miguelnyc703 has asked for the wisdom of the Perl Monks concerning the following question:
Can someone please explain why this is matching at all?
In the string, 'CME.' is a literal match (ok), followed by an optional 'b' (ok, it is present), but then the forward slash '/' should not match the negated character set as this is clearly saying "anything except / or ." The above was also tested using an actual Perl script:$ echo 'CME.b/ESM8' | grep -P '^CME\.b?[^/.]' CME.b/ESM8
but that also indicates a match: <code> $ ./foo.pl yes {/code} I've been writing Perl regexes for years but this is really puzzling me. Tanks! Miguel#!/usr/bin/perl use strict; use warnings; my $string = 'CME.b/ESM8'; if ( $string =~ /^CME\.b?[^\/.]/ ) { print "yes\n"; } else { print "no\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Strange negated character class behavior
by tybalt89 (Monsignor) on Nov 08, 2018 at 22:56 UTC | |
|
Re: Strange negated character class behavior (updated)
by AnomalousMonk (Archbishop) on Nov 08, 2018 at 23:10 UTC | |
|
Re: Strange negated character class behavior
by ikegami (Patriarch) on Nov 09, 2018 at 13:19 UTC | |
|
Re: Strange negated character class behavior (re debug rxrx)
by Anonymous Monk on Nov 09, 2018 at 03:43 UTC | |
|
Re: Strange negated character class behavior
by Anonymous Monk on Nov 09, 2018 at 18:33 UTC |