dlclark / regexp2

A full-featured regex engine in pure Go based on the .NET engine

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Regex Multiline

SmallSmartMouse opened this issue · comments

a regex= ^(ac|bb)$\n, but this i dont use option Multiline,I think it will error when MustCompile,but it not ,and can match string "ac\n",so how can i do ,it will throw an error

Hello!
I believe this is a difference in behavior between PCRE and Javascript/RE2 regex engines. You can see this by changing the engine on the left side here: https://regex101.com/r/hUAttU/1
Go (RE2) and Javascript don't match, but PHP/PCRE and Python do.

The definition for $ in PCRE-based engines without Multiline is: $ asserts position at the end of the string, or before the line terminator right at the end of the string (if any). That means that the pattern $\n will match the text \n -- the $ will match the newline but is zero-width so it won't advance the pattern, and then the explicit \n will match and advance the pattern.

Honestly the behavior is counter-intuitive, but it's an edge case that I maintain for compatibility with the other Javascript engines (including C#, Python, and PCRE). I recently added an RE option to increase compatibility with existing Go regex's when needed -- would you like me to add this case to it?

If I misunderstood please provide a code example so I can review it in more detail.

Thanks!

Sorry, just spotted this. I'd like that fixed at least for ECMAScript mode if possible. Thanks!

I’ll have to put this change behind the RE2 or EMCAScript options.

I might have some time to do it this week.

Thanks!