Repository navigation
fix: lazy quantifiers matched greedily (#175) - #181
Open
Arthur031221 wants to merge 1 commit into
Open
Arthur031221 wants to merge 1 commit into
Arthur031221 wants to merge 1 commit into
Conversation
The char class searcher and the composite searcher scan greedily, so `\d+?` on "11" returned [0 2] instead of [0 1]. Patterns with a lazy quantifier now use another strategy there. Co-authored-by: Andrey Kolkov <3740898+kolkov@users.noreply.github.com>
Arthur031221
force-pushed
the
bugfix/issue-175-lazy-quantifier
branch
from
October 9, 2026 22:17
a730b81 to
562dac8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Covers the cases in #175 that go through the char class and composite searchers, building on the ones @kolkov posted there (the first five rows of the new test).
The char class searcher and the composite searcher scan greedily, so they ignored lazy quantifiers.
\d+?on"11"returned[0 2]where the stdlib returns[0 1] [1 2], and\w+?\s??\w?on"1A\nc"returned[0 4]where the stdlib returns[0 2] [3 4]. Patterns with a lazy quantifier now skip those two searchers. That's slower on those paths:\d+?over 100 KB goes from about 75 to 371 microseconds.Two related cases aren't fixed here. The submatch of
(\d+?)on"11"is still[0 2 0 2]because the OnePass DFA never stops at a lazy match..*?aon"xaax"still returns[0 3]because the reverse suffix search takes.*?for.*.Added
TestIssue175_LazyQuantifier, run withgo test ./....Assisted by Claude/Codex.
Co-authored-by: Andrey Kolkov 3740898+kolkov@users.noreply.github.com