Skip to content

[bug] Lookahead inside quantified group produces wrong results #28

@jbachorik

Description

@jbachorik

Description

A lookahead assertion ((?=...) or (?!...)) inside a quantified group (e.g. (?:(?=\d)\d)+) does not work correctly. The pattern matches nothing regardless of input.

Reproduction

ReggieMatcher m = Reggie.compile("(?:(?=\\d)\\d)+");
m.find("123"); // returns false — WRONG, should be true
m.find("abc"); // returns false — correct, but for wrong reason

Root cause

The DFA_UNROLLED_WITH_ASSERTIONS strategy does not correctly handle lookahead assertions nested inside quantified groups. The lookahead state is not re-evaluated on each iteration of the quantified loop.

Current mitigation

FallbackPatternDetector detects a lookahead AssertionNode inside a QuantifierNode's subtree and falls back to java.util.regex.

Fix direction

When a quantified group contains a lookahead, the assertion must be re-evaluated from the current position on each iteration of the loop in the generated bytecode.

Impact

High — patterns that use lookahead constraints inside repeated groups silently produce wrong results.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions