You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Activity
dlclark commentedon 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$\nwill match the text\n-- the$will match the newline but is zero-width so it won't advance the pattern, and then the explicit\nwill 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
REoption 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!
dop251 commentedon Aug 25, 2020
Sorry, just spotted this. I'd like that fixed at least for ECMAScript mode if possible. Thanks!
dlclark commentedon 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.
dop251 commentedon Aug 26, 2020
Thanks!
fixes dlclark#24 changes $ behavior in singleline when using RE2 and …