Re:\d less efficient than [0-9]
by jeltz on Sunday May 19, 2013 @06:22PM
(#5734647)
Happens in Perl but not ruby or PostgreSQL.
[ Parent
| on HN ]
Doesn't happen in Perl for me:
pfedor@Pawels-iMac:~$ perl -ne 'print "Digit!\n" if /\d/'
af
3
Digit!
23fa3
Digit!
asdf
١٢٣٤٥٦٧٨٩۰۱۲۳۴۵۶۷۸۹
৩৪৫৬৭৮৯੦੧੨੩੪੫੬੭੮੯૦૧૨૩૪૫
୧୨୩୪୫୬୭୮
౨౩౪౫౬౭౮౯೦೧೨೩೪೫೬೭೮೯൦൧൨൩൪൫൬൭൮൯๐๑๒๓๔๕๖๗๘๙໐໑໒໓
234
Digit!
(perl from Macports and perl from /usr/bin/perl behave the same in this respect.)You have to tell to interpret stdin as UTF-8 (flag -C) - then it works: https://news.ycombinator.com/item?id=5734641
Good to know, thanks.
I'd argue that perl gets it right--as the default behavior, this behavior would gravely violate the principle of least surprise, but for the 0.01% of people who want \d to match ੧, there's no harm to making it available as an option you need to specifically request.