A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2017-December/151067.html below:

[Python-Dev] Zero-width matching in regexes

[Python-Dev] Zero-width matching in regexesTerry Reedy tjreedy at udel.edu
Tue Dec 5 15:26:04 EST 2017
On 12/4/2017 6:21 PM, MRAB wrote:
> 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""".

Is this different from current re or regex?

> 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.
> 
> Example:
> 
>  >>> print([m.span() for m in re.finditer(r'|.', 'a')])
> [(0, 0), (0, 1), (1, 1)]
> 
> re.findall, re.split and re.sub should work accordingly.
> 
> If re.finditer finds n matches, then re.split should return a list of 
> n+1 strings and re.sub should make n replacements (excepting maxsplit, 
> etc.).


-- 
Terry Jan Reedy

More information about the Python-Dev mailing list

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