Why \d is slower than [0-9]

I learned an interesting thing today about regular expressions via this stackoverflow question. \d, commonly used as a shorthand for digits (which we usually think of as 0-9) actually checks against all valid unicode digits.

Given that, it makes sense why \d in a regular expression is slower, since it has to check against all possible digit types. In C# you can limit the regular expression to use ECMAScript standards which doesn’t include the full unicode subset of digits.

While I’m neither the question asker nor answerer, I wanted to share since this is something I didn’t know about before.

Post a comment

You may use the following HTML:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>