Skip to content

Java Regex Z Assertion - #1755

Merged
arcuri82 merged 3 commits into
masterfrom
java-regex-Z-assertion
Sep 17, 2026
Merged

arcuri82 merged 3 commits into
masterfrom
java-regex-Z-assertion

Conversation

@lmasroca

Copy link
Copy Markdown
Collaborator

Adds support for Java regex \Z assertion and linebreak matcher \R:

  • \Z is an end of input assertion that allows a final line terminator. This assertion matches at the end of the input or just before a line terminator with no characters following after it. This assertion's allowed terminators change depending on flag d, UNIX_LINES. For example ^(?s)\Z.* matches with "", \n, etc. Unlike \z which just forces all following genes to zero-width, \Z may also try to force a line terminator onto one of the following genes and the rest to zero-width.
  • \R matches any Unicode linebreak sequence, is equivalent to \r\n|[\n-\r\u0085\u2028\u2029]. Unlike the previous mention, this is not an assertion, so it produces a sequence of characters (unlike assertions). This is represented by building a DisjunctionListRxGene that can produce the same characters as its Java Pattern counterpart. This escape's characters are not modified by flags.

Note: both of these recognize some single character line terminator sequences (like \n or \u2029) and one two-character sequence \r\n (this sequence is a single line terminator, CRLF).

@lmasroca
lmasroca marked this pull request as ready for review September 13, 2026 22:03
@lmasroca
lmasroca requested a review from jgaleotti September 13, 2026 22:03
@jgaleotti
jgaleotti requested a review from arcuri82 September 15, 2026 16:26
@arcuri82
arcuri82 merged commit 71cb940 into master Sep 17, 2026
31 checks passed
@arcuri82
arcuri82 deleted the java-regex-Z-assertion branch September 17, 2026 08:20
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.

3 participants