3 ms·
This is bizarre. I thought [0-9] was supposed to match only 0-9 (the 10 digits), while \d was meant to match all digits including the various Unicode variations
by cpburns2009 8y ago
This is bizarre. I thought [0-9] was supposed to match only 0-9 (the 10 digits), while \d was meant to match all digits including the various Unicode variations.
- nitely 8y ago0-9 is defined as a [ascii] range, so you are correct.
- jwilk 8y agoThis is true for many regular expression dialects. But this bug about POSIX regular expressions. POSIX doesn't define \d, and it defines ranges such as [0-9] only in the POSIX locale. Historically, glibc considered such ranges in the context of locale's collation order. For example, in Estonian locale, [a-z] doesn't include the letters tuvwxy, because that's how Estonian alphabet works: https://en.wikipedia.org/wiki/Estonian_orthography#Alphabet https://en.wikipedia.org/wiki/Estonian_orthography#Alphabet This (somewhat surprising) semantics of character ranges is not new, but the recent changes in glibc made it more spectacular.
- kazinator 8y ago\d is a Perlism. Yes, [0-9] is supposed to be locale independent, which is related to the fact that ISO C requires the digit characters '0' through '9' to be consecutive. The same is not true of [A-Z], which doesn't necessarily include just the upper-case English letters from ASCII. It is locale-specific, in fact. The POSIX digit matcher is [[:digit:]]. It is related to the C isdigit function from <ctype.h>. Those functions have regex counterparts, like isalnum -> [[:alnum:]] and so on. The way those functions have locale-dependent behavior is linked to how the corresponding regex classes have locale-dependent behavior.