05.12.17 01:21, MRAB пише: > I've finally come to a conclusion as to what the "correct" behaviour of > zero-width matches should be: """always return the first match, but > never a zero-width match that is joined to a previous zero-width match""". > > If it's about to return a zero-width match that's joined to a previous > zero-width match, then backtrack and keep on looking for a match. Isn't this how sub(), findall() and finditer() work in regex with VERSION1? I agree that this behavior looks most logical and self-consistent. Unfortunately the different behavior of re.sub() is documented explicitly: "Empty matches for the pattern are replaced only when not adjacent to a previous match, so sub('x*', '-', 'abc') returns '-a-b-c-'." And there a special purposed test for this. One time the behavior was changed when the re implementation was changed from pre to sre, but the older behavior was restored. [1] [2] [1] https://bugs.python.org/issue462270 [2] https://github.com/python/cpython/commit/21009b9c6fc40b25fcb30ee60d6108f235733e40
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4