Regex doesn't match end of line with both carriage return and line feed


#1

I was trying to use the Regex feature where ^ and $ match the start and end of individual lines instead of the whole string, and I noticed that:

$ match(r"does$"m, "this does\r\nnot work")

$ match(r"does$"m, "this does\nwork")
RegexMatch("does")

Is this as expected, or is this a bug?


#2

This behavior depends on how the underlying regexp library was compiled. You can do this to override the default behavior:

julia> match(r"(*ANYCRLF)does$"m, "this does\r\nso work")
RegexMatch("does")

(See the Wikipedia article on PCRE for details, especially alternative versions of the EOL spec.)


#3

Great explanation, thank you!