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

\Z not work on regexp2.RE2 mode #46

Closed
yywing opened this issue Jan 15, 2022 · 1 comment
Closed

\Z not work on regexp2.RE2 mode #46

yywing opened this issue Jan 15, 2022 · 1 comment

Comments

@yywing
Copy link

yywing commented Jan 15, 2022

s1  := `^Google\nApple$`
s2  := `^Google\nApple\Z`
data := "Google\nApple\n"
// will get result
re, err := regexp2.Compile(s, regexp2.Singleline)
// will not get result
re, err := regexp2.Compile(s, regexp2.Singleline|regexp2.RE2)

Why?

@dlclark
Copy link
Owner

dlclark commented Jan 15, 2022

This is because of #24. With RE2 option in Singleline mode we change \Z and $ to mean "End of String" -- so the extra \n at the end prevents a match (which matches the RE2 behavior). The .NET engine behavior is a bit different and allows the trailing \n.

@dlclark dlclark closed this as completed Jan 15, 2022
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

2 participants