开发者

Does python have the equivalent of Perl's regex "local" variable?

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 开发者_Go百科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.


No. You need a grammer - pyparsing is nice (and easy)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜