Skip to content

Java regex quote (\Q...\E) bug fix#1644

Merged
arcuri82 merged 5 commits into
masterfrom
java-regex-quote-bug
Jul 20, 2026
Merged

Java regex quote (\Q...\E) bug fix#1644
arcuri82 merged 5 commits into
masterfrom
java-regex-quote-bug

Conversation

@lmasroca

Copy link
Copy Markdown
Collaborator

Fixed a bug with java regex quoting.

Currently, when multiple quotes appear in one regex we took the first \Q and matched it with the last \E, ignoring the rest, this results in regex like ^(\\Q81\\E(x|X)(a|A)\\Q3\\E(p|P)(x|X)(d|D))$ sampling things like 81\\Exa\\Q3\\Epxd instead of 81xa3pxd. We also needed to explicitly allow all lexer tokens on the quoteChar parser rule before.

This PR solves both, by splitting the RegexJava.g4 combined grammar into RegexJavaParser.g4 (parser grammar) and RegexJavaLexer.g4 (lexer grammar) we can now use lexer modes to define separate set of lexer tokens depending on the context. This lets us solve the two problems.

Note: the diff might look large as the combined file got deleted and two new files appeared but there where only some minor changes to the actual grammar regarding quoting.

@lmasroca
lmasroca requested a review from jgaleotti July 18, 2026 00:16
@jgaleotti
jgaleotti requested a review from arcuri82 July 20, 2026 16:54
@arcuri82
arcuri82 merged commit aab346d into master Jul 20, 2026
31 checks passed
@arcuri82
arcuri82 deleted the java-regex-quote-bug branch July 20, 2026 18:57
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