I 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/' ੧
You 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 :)
\d less efficient than [0-9]
21–30 of 80 posts
Re: \d less efficient than [0-9]
#22Short answer: \d includes all the Unicode characters from http://www.fileformat.info/info/unicode/category/Nd/list.htm
Is that actually a good thing? If I'm using \d to validate numbers (for example to check before string to int conversion, or IP address, phone number, or any other use), other unicode digits are not helpful to me. It's great to support unicode, but I don't think the \d should have been extended this way. Add a \ud or something.
Re: \d less efficient than [0-9]
#23Re: \d less efficient than [0-9]
#24Earlier quoted context omitted.
Anyone know if this happens in other languages?
Doesn't appear to in JavaScript: "੧".match(/\d/); //null (Incidentally, this may explain the finding from http://stackoverflow.com/a/16622773/172322 , as to why adding the RegexOptions.ECMAScript flag in the C# code eliminates the performance gap)
print re.match(r'\d','੧')
None
Re: \d less efficient than [0-9]
#25Earlier quoted context omitted.
...at least in C# regexes.
Anyone know if this happens in other languages?
Re: \d less efficient than [0-9]
#26IMO you should be running something for much longer, to protect against random short spurious events. e.g. a task reschedule, interrupts, etc could add significant variances. It wouldn't hurt to add a few more zeros to the loop and wait a minute for the results.
Re: \d less efficient than [0-9]
#27Earlier quoted context omitted.
Anyone know if this happens in other languages?
Not true for Go http://play.golang.org/p/ls96RxJxpz
Re: \d less efficient than [0-9]
#28Earlier quoted context omitted.
Doesn't appear to in JavaScript: "੧".match(/\d/); //null (Incidentally, this may explain the finding from http://stackoverflow.com/a/16622773/172322 , as to why adding the RegexOptions.ECMAScript flag in the C# code eliminates the performance gap)
Nor in python: print re.match(r'\d','੧') None
re.match(r'\d', u'੧', re.U)
sys.version
2.7.3 (default, Mar 4 2013, 14:57:34) \n[GCC 4.7.2]Re: \d less efficient than [0-9]
#29The test code creates a new regex every time, would be interesting to see how it works with a compiled and reused regex.
Re: \d less efficient than [0-9]
#30I wonder what kind of security vulnerabilities could be looming in validators not expecting non-ascii 0-9 digits and using this regex?