Can someone explain how this interaction in ghci is possible?
*Main Text.Regex.Posix> "d1" =~ "\\d" :: String
"d"
*Main Text.Regex.Posix> "d1" =~ "\\d" :: Int
1
I thought that \d
standed for digit, so I don't understand how it can match the character d
and not the character 1
present on the string.
Note: Using ghci 7.10.3
The Text.Regex.Posix
module only supports c posix regex api. POSIX regex syntax does not define \d
as a shorthand character class for digits, instead, it has [:digit:]
POSIX character class that must be used inside bracket expressions, e.g. [[:digit:]]
. However, it is as easier and shorter to use [0-9]
to match regular ASCII digits.
To use \d
in your patterns, you may want to use Text.Regex.PCRE.
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