Skip to content

Fix multiline RegEx iteration (breaking change for .Multiline usage) #5220

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

Merged
merged 1 commit into from
May 26, 2025

Conversation

Feoramund
Copy link
Contributor

Fixes #5017
Supercedes #5027 by @jist99

In .Multiline mode:

  • ^ is now defined to assert the start of the string or that a "\n" or "\r" rune was parsed on last VM dispatch.
  • $ is now defined to consume a newline sequence of "\n", "\r", or "\r\n" or to assert the end of the string.

This patch is similar to #5027 except that it consumes the newline at the end of a string, not at the start, and this is returned to the user, which should be more sensible. To clarify, every multiline iteration will receive the newline if one is present and only on the final line will the resulting capture have no terminating newline, as this distinction could be relevant to some programs.

I've added a few more tests to define the expected behavior, but I'd like to know if anyone can poke any holes in this.

This change is breaking for any usage of .Multiline, as the semantics have changed.

In `.Multiline` mode:

- `^` is now defined to assert the start of the string or that a "\n" or
  "\r" rune was parsed on last VM dispatch.

- `$` is now defined to consume a newline sequence of "\n", "\r", or
  "\r\n" or to assert the end of the string.
@Kelimion
Copy link
Member

Seems like a sensible approach. If people don't want the newlines to be part of the capture, they can strip the result before using, or () the part between the anchors.

@Kelimion Kelimion merged commit d156c26 into odin-lang:master May 26, 2025
13 of 14 checks passed
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

Successfully merging this pull request may close these issues.

Regex .Multiline consuming \n with $
2 participants