dlclark / regexp2

A full-featured regex engine in pure Go based on the .NET engine
MIT License
997 stars 84 forks source link

\Z not work on regexp2.RE2 mode #46

Closed yywing closed 2 years ago

yywing commented 2 years ago
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 commented 2 years ago

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.