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.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.