Comment on \d less efficient than [0-9]Comments−rwmj13yI was a bit surprised that Perl does not seem to be matching Unicode digits. Anyone know why? $ echo '0' | perl -pe 'print "yes: " if m/\d/' yes: 0 $ echo '੧' | perl -pe 'print "yes: " if m/\d/' ੧−xonea13yYou have to tell perl to expect utf8 from stdin (switch -C). $ echo '੧' | perl -C -pe 'print "yes: " if m/\d/' and $ perl -e 'use utf8; print "yes\n" if "੧" =~ m/\d/;' both work :)−pooriaazimi13y`man perlunicode` is chockfull of utf8-related stuff (and it's looong): http://perldoc.perl.org/5.14.0/perlunicode.html−damncabbage13yDitto PHP: php > var_export(preg_match("/\d/", "1")); 1 php > var_export(preg_match("/\d/", "۳")); 0−jpiasetz13yAdd /u php > var_export(preg_match("/\d/u", "۳"));−bellbind13yIt does. See http://ideone.com/Q1lf1M−ars13yTry: utf8::upgrade($string) And/or: use feature 'unicode_strings'−netfeed13yThe documentation says \d should match if you use /u on the regex
Comments
I was a bit surprised that Perl does not seem to be matching Unicode digits. Anyone know why?
You have to tell perl to expect utf8 from stdin (switch -C).
both work :)`man perlunicode` is chockfull of utf8-related stuff (and it's looong): http://perldoc.perl.org/5.14.0/perlunicode.html
Ditto PHP:
Add /u
It does. See http://ideone.com/Q1lf1M
Try:
And/or:The documentation says \d should match if you use /u on the regex