Skip to content

Regex Multiline  #24

Closed
Closed

Description

@SmallSmartMouse

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

Activity

  1. dlclark commented on Feb 7, 2020

    @dlclark
    Owner

    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!

  2. dop251 commented on Aug 25, 2020

    @dop251
    Contributor

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

  3. dlclark commented on Aug 25, 2020

    @dlclark
    Owner

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

    I might have some time to do it this week.

  4. dop251 commented on Aug 26, 2020

    @dop251
    Contributor

    Thanks!

  5. added a commit that references this issue on Jun 10, 2024
    0537a49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions