Introduction
I am using the Haskell Text.Regex library and I want to match some characters that usually make sense in regular expressions. According to the Text.Regex documentation ,
Regular expression syntax is ... egrep expression (ie POSIX "extended" regular expressions).
And, apparently, escaping in POSIX Extended Regular Exions (ERE) uses a backslash [as opposed to POSIX Basic Regular Expressions (BRE) .
Problem
However, when I try to do something like this:
> import Text.Regex > matchRegex (mkRegex "\*") "*"
I get the following error:
<interactive>:1:23: lexical error in string/character literal at character '*'
The same thing happens no matter what character I put after \ .
workaround
I could do something like this:
> matchRegex (mkRegex "[*]") "*" Just []
but it seems to be a hack, especially if I want to avoid a few things in a row (for example, mkRegex "[[][(][)][]]" that matches [()] ).
Question
Is this the only way to escape to POSIX ERE? Why doesn't the Haskell Text.Regex library support \ , as it seems, it should?
source share