Do Python regular expressions have an equivalent to Ruby's atomic grouping?

后端 未结 4 1023
情深已故
情深已故 2020-12-08 19:39

Ruby\'s regular expressions have a feature called atomic grouping (?>regexp), described here, is there any equivalent in Python\'s re module?

4条回答
  •  囚心锁ツ
    2020-12-08 20:10

    It would seem not.

    http://www.regular-expressions.info/atomic.html

    Atomic grouping is supported by most modern regular expression flavors, including the JGsoft flavor, Java, PCRE, .NET, Perl and Ruby.

    You can emulate the non-capturing-ness of them by using non-capturing groups, (?:RE), but if I'm reading it right, that still won't give you the optimization benefits.

提交回复
热议问题