While I have been using \p{Alpha} and \p{Space} for quite some time in my regular expressions I just came across \p{Digit}, but I couldn't find any information about what the up- or downsides are compared to the normal \d that I normally use. What are the key differences between those to?
\d matches only ASCII digits, i.e. it is equivalent to the class [0-9]. \p{Digit} matches the same characters as \d plus any other Unicode character that represents a digit. For example to match the arabic zero (code point U+0660):
"\u0660"
# => "٠"
"\u0660" =~ /\d/
# => nil
"\u0660" =~ /\p{Digit}/
# => 0
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