While searching for a solution to a python regular expression problem I found this page which demonstrates that [some version of] perl allows variables within regular expressions.
e.g. a perl regex something like:
^(?{ local $d=0}\((?{ $d++ }.*?\)(?d--)
Where variable $d
is incremented and decremented depending on which part of the regex you're in.
(See the link for a real example)
Is there something equivalent in python?
Note: I realize that you can achieve this goal with a real parser and a grammar, but I don't want to add another dependency to overcome this tiny problem for a script I'm writing. And no, this script doesn't have to have nine nines of uptime.