graff has asked for the wisdom of the Perl Monks concerning the following question:
Reading perlre, I would expect the following two regexes to match the same set of characters (in the ASCII range, at least), because they are said to be "equivalent":
But when I tried the following little test snippet, I got a bit of a surprise:/[[:punct:]]/ /\p{IsPunct}/
Actually, when I look at the output, there seems to be some rhyme and reason to the discrepancies, so it looks like a "feature" (not a bug) to have the two different notions of "punctuation" (and the docs should be updated accordingly):for $x ( 0x20 .. 0x7e ) { $_ = chr( $x ); $res = ( /[[:punct:]]/ ) ? "matches :punct:" : "is not a :punct:" +; $res .= ( /\p{IsPunct}/ ) ? " matches {IsPunct}" : " fails on {Is +Punct}"; printf( " 0x%x (%3d.) %s %s\n", $x, $x, $_, $res ) if ( $res =~ /m +atches/ ); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: [[:punct:]] vs. {IsPunct} in 5.8
by particle (Vicar) on Nov 02, 2003 at 14:26 UTC | |
by dakkar (Hermit) on Nov 02, 2003 at 20:45 UTC | |
by graff (Chancellor) on Nov 02, 2003 at 17:03 UTC | |
|
Re: :punct: vs. {IsPunct} in 5.8
by liz (Monsignor) on Nov 02, 2003 at 09:51 UTC |