Skip to content

'Overlapping' empty match suppression algorithm hides real non-empty matches #1358

Description

@orlp

What version of regex are you using?

regex == 1.12.3

Describe the bug at a high level.

regex suppresses empty matches in find_iter() that start at the end of the previous match because it considers them overlapping with the previous match. I disagree with this interpretation, but let's assume that's the case.

regex however still remembers the suppressed empty match and uses it to suppress otherwise completely non-overlapping non-empty matches as well.

What are the steps to reproduce the behavior?

let pattern = "a?|b";
let haystack = "aba";
dbg!(regex::Regex::new(pattern).unwrap().find_iter(haystack).collect::<Vec<_>>());

What is the actual behavior?

We see the following matches:

[
    Match {
        start: 0,
        end: 1,
        string: "a",
    },
    Match {
        start: 2,
        end: 3,
        string: "a",
    },
]

What is the expected behavior?

I would expect a match of "" or "b" (or both) at start: 1, but not that there is zero matches starting at index 1.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions