Skip to content

Ability to query minimum/maximum length of regex #513

@MegaIng

Description

@MegaIng

For the lark parsing library we use the (sadly private) stdlib re._parser library to query the minimum and maximum length of a regex:

https://github.com/lark-parser/lark/blob/942366b49247e996e387cb901ed96c7d861382a0/lark/utils.py#L132-L156

As can be seen from the snippet, since we also support using regex instead of re, we need to take special care when encountering regex specific syntax, like nested sets category patterns. The only value that needs to be correct is if minimum length is 0 or greater since we depend on Regular Expressions being non-empty in a few places.

It would be nice if there was a way a query the minimum and maximum match size from a compiled regex object. The stdlib re module is lower priority since there there is at least a way to accesses this information reliably, but I am probably also going to make a request there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions