Skip to content

False positive: Unmatchable dollar in regular expression with lookahead assertion #20429

@sam-maloney

Description

@sam-maloney

Description of the false positive

I get false positives for the following expression (using the Python re module):

r"^(?=\[.*]$|[^][]*$)\[?[1-9]\d*(\+|-[1-9]\d*)(:[1-9]\d*(:[+*^])?)?]?$"

Unmatchable dollar in regular expression
This regular expression includes an unmatchable dollar at offset 9.
This regular expression includes an unmatchable dollar at offset 17.

It seems to be complaining about the dollars in the forward lookahead assertion, i.e. (?=\[.*]$|[^][]*$), but both of those occur at the end of their respective alternatives, so they can match fine, and because it's just a lookahead assertion it doesn't actually consume the match and the following expression can still be tested as normal.

Code samples or links to source code

The regex has been developed/tested here: https://regex101.com/r/G4MP54

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