Skip to content

find/captures disagree about match when using $ or \z #334

@CmdrMoozy

Description

@CmdrMoozy

I believe I have found a bug in this library. I've tried to condense it down into the simplest possible test case which reproduces the problem:

#[test]
fn test_end_of_text() {
    let re = regex!(r"a(b*(X|\z))?");
    let text = "abcbX";
    let ma = re.find(text).unwrap().as_str();
    let mb = re.captures(text).unwrap().get(0).unwrap().as_str();
    assert_eq!("a", ma);
    assert_eq!(ma, mb);
}

I would expect this test case to pass. The first assert_eq! does, but the second assert_eq! reports that re.captures( actually returned "ab" instead of just "a". It seems like (b*(X|\z))? matches the b following the a and returns it as part of the full capture group, even though the following character c doesn't match X|\z. Interestingly, this only seems to happen when using captures, and not find.

Metadata

Metadata

Assignees

No one assigned

    Labels

    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