leftmost longest match (of disjunctions) ; greediness of "|"
Joerg Schuster
js at cis.uni-muenchen.de
Wed Dec 3 07:37:03 EST 2003
"Fredrik Lundh" <fredrik at pythonware.com> writes:
> you can use "sre_parse.parse(x).getwidth()" on a subexpression, to
> get the shortest/longest possible match.
>
> >>> from sre_parse import parse
> >>> parse("a?").getwidth()
> (0, 1)
> >>> parse("ab").getwidth()
> (2, 2)
> >>> parse(".+").getwidth()
> (1, 65535)
>
> (where >=65535 should be interpreted as "any number")
>
> </F>
Thanks for the tip.
More information about the Python-list
mailing list