in reply to negating POSIX regexp classes doesn't work as expected
Character classes should be used like this: [xyz[:class:]XYZ]; the [] are part of the character class.
This is what you want:
#!/usr/bin/perl my $a = "123{12\n"; print "ACK non-digit!\n" if ($a =~ /[[:^digit:]]/); print "ACK \\D!\n" if ($a =~ /\D/);
Update: Looking over perlre I see how there could be some confusion. It describes, e.g., [:digit:] as "equivalent" to \d, but they are not quite equivalent, because, whereas \d may be used either inside or outside a regular Perl character class, [:digit:] can be used only within a Perl character class. This is what I mean:
(I realize that I'm using the term "character class" in two distinct ways, one to refer to the usual Perl regexp construcs, such as [0-6:-], and the other to refer to POSIX character classes; but in doing so I'm just following perlre's terminology.)DB<1> $s = 123 DB<2> x $s =~ /(\d)/g 0 1 1 2 2 3 DB<3> x $s =~ /([\d])/g 0 1 1 2 2 3 DB<4> x $s =~ /([:digit:])/g empty array DB<5> x $s =~ /([[:digit:]])/g 0 1 1 2 2 3
the lowliest monk
|
|---|