Skip to content

regex and regex_lite disagree on whether repetition operators associate with flag-setters #1359

Description

@orlp

What version of regex are you using?

regex == 1.12.3
regex_lite == 0.1.9

Describe the bug at a high level.

regex and regex_lite both support "flag-setters". They have the following syntax: (?flags). This looks superficially like a group but only sets a flag.

However the two tools disagree on whether this element of the syntax associates with a repetition operator.

What are the steps to reproduce the behavior?

let pattern = "a(?u)*";
let haystack = "aaa";
dbg!(regex_lite::Regex::new(pattern).unwrap().find_iter(haystack).collect::<Vec<_>>());
dbg!(regex::Regex::new(pattern).unwrap().find_iter(haystack).collect::<Vec<_>>());

What is the actual behavior?

regex_lite does not associate the repetition operator with the flag setter (?u), so it will simply behave equivalent to a* and match the three a's.

regex does associate the repetition operator with the flag setter, and gives an error:

regex parse error:
    a(?u)*
         ^
error: repetition operator missing expression

What is the expected behavior?

I can see something for both approaches but they should probably be equivalent.

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