Skip to content

[bug] Combined lookbehind + lookahead (sandwich pattern) always fails #31

@jbachorik

Description

@jbachorik

Description

A pattern that uses both a lookbehind and a lookahead assertion together always returns false, even for inputs that clearly should match.

Reproduction

ReggieMatcher m = Reggie.compile("(?<=\\[)[^\\]]+(?=\\])");
m.find("[value]"); // returns false — WRONG, should be true (captures "value")
m.find("value");   // returns false — correct

// Another example:
Reggie.compile("(?<=\\d)[a-z]{1,4}(?!\\d)").find("3abc"); // should be true

Root cause

The DFA_UNROLLED_WITH_ASSERTIONS strategy does not correctly compose lookbehind and lookahead assertions in the same pattern. After the lookbehind succeeds and the body matches, the lookahead check is evaluated against an incorrect position.

Current mitigation

FallbackPatternDetector detects any pattern containing both a lookbehind and a lookahead assertion and falls back to java.util.regex.

Fix direction

In the assertion-aware DFA/NFA path: after the body match, the lookahead must be evaluated from the current end position. Likely requires fixing position tracking between lookbehind, body, and lookahead evaluation phases.

Impact

High — sandwich patterns (extract content between delimiters) are very common and completely non-functional without the fallback.

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