Skip to content

Unexpected match with end anchor in group #921

Closed
@vthib

Description

@vthib

What version of regex are you using?

1.6.0

Describe the bug at a high level.

The regex (a$)b$ matches on input ab which is not expected.

What are the steps to reproduce the behavior?

fn main() {
    let regex = regex::Regex::new("(a$)b$").unwrap();
    println!("match: {:?}", regex.find("ab"));
    println!("captures: {:?}", regex.captures("ab"));
}

What is the actual behavior?

This prints:

match: Some(Match { text: "ab", start: 0, end: 2 })
captures: None

What is the expected behavior?

The regex should not match. The capture call gives the expected result, but not the find call.

a$b$ and (a$)b display the expected behavior, so this seems to be a weird corner case.

My first hypothesis was that it is caused by an invalid suffix extraction:

$ regex-debug prefixes '(a$)b$'
Cut(a)
$ regex-debug suffixes '(a$)b$'
Complete(ab)
$ regex-debug prefixes 'a$b$'
Cut(a)
$ regex-debug suffixes 'a$b$'
Cut(b)

But the regex (a$)b does not have the bug, and yet has the same suffix extraction:

$ regex-debug suffixes '(a$)b'
Complete(ab)

So i'm not sure it is related to this.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions