Open raxod502 opened 4 years ago
regex-tdfa seems to have a non-standard multiline mode that combines what is usually known as "multiline" (i.e. having "^" and "$" match at the beginning/end of individual lines, not just the whole string) with inverse "dotall" and also disables matching newlines in inverted character classes (so you can't even use e.g. [^&]
as you mentioned).
You can match a newline using "(.|\n)"
, but only with an actual newline in the pattern (since \n
is just n
to regex-tdfa).
> ("\n" =~~ "(.|\n)") :: Maybe String
Just "\n"
It does recognise [[:space:]]
though, so this works as well (in case your pattern is e.g. user input that can't contain a newline):
> ("\n" =~~ "(.|[[:space:]])") :: Maybe String
Just "\n"
If you don't care about "^" and "$" but want "." to match newlines, use multiline = False
:
> let p = makeRegexOpts defaultCompOpt { multiline = False } defaultExecOpt "."
> p `matchM` "\n" :: Maybe String
Just "\n"
Thanks for the pointer. I think this issue then becomes a request for the documentation to include this helpful information.
In GHCI:
The documentation says multiline matching should be enabled by default, but just to double-check, I tried enabling it explicitly:
No luck. The same thing happens for inverted character classes (e.g.,
[^&]
instead of.
). Am I misunderstanding how to get my regex to match newlines?