Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regex Multiline #24

Closed
SmallSmartMouse opened this issue Feb 7, 2020 · 4 comments
Closed

Regex Multiline #24

SmallSmartMouse opened this issue Feb 7, 2020 · 4 comments

Comments

@SmallSmartMouse
Copy link

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

@dlclark
Copy link
Owner

dlclark commented Feb 7, 2020

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!

@dlclark dlclark closed this as completed Aug 23, 2020
@dop251
Copy link
Contributor

dop251 commented Aug 25, 2020

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

@dlclark
Copy link
Owner

dlclark commented Aug 25, 2020

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

I might have some time to do it this week.

@dlclark dlclark reopened this Aug 25, 2020
@dop251
Copy link
Contributor

dop251 commented Aug 26, 2020

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants