I often see [0-9] used in .NET regular expression answers on Stack Overflow instead of \d. I’ve asked why, and the answer tends to be “\d matches more than just [0-9]”. So what more does it match? This table says it matches decimal digits. And what about \p{Nd}?
Or is there no difference, and this is just good practice because of some other regex engine?
I think the answer is also in the linked reference:
\d matches any decimal digit. It is equivalent to the \p{Nd} regular expression pattern, which includes the standard decimal digits 0-9 as well as the decimal digits of a number of other character sets.
So \d can match things like decimal digits in the Arabic character set, which wouldn't be matched with [0-9].
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With