I’m having some trouble with regexes in haskell. Specifically:
Prelude Text.Regex.Posix> "1" =~ "\d" :: Bool
<interactive>:1:10:
lexical error in string/character literal at character 'd'
Prelude Text.Regex.Posix> "1" =~ "\\d" :: Bool
False
Prelude Text.Regex.Posix> "1" =~ "\\\\d" :: Bool
False
Does Haskell not have the \d or \s or other such convenient escape codes? Yes, I know I can do [0-9] instead, but the escape codes can be so much more convienient for complex regexes. Am I missing something obvious here?
I don’t know much about the Haskell regex packages, but from your examples above with “Text.Regex.Posix”, I might infer that you’re dealing in POSIX regular expressions. Escape sequences such as \d and \s aren’t part of POSIX regex syntax, and I believe originated with Perl and have since propagated into other languages.