GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • [Python-Dev] 3.7.0a3 still open
  • [Python-Dev] Zero-width matching in regexes
  • [ date ]
  • [ thread ]
  • [ subject ]
  • [ author ]

This view

  • Original page
  • New address

GeezerVison is showing mail.python.org — [Python-Dev] Zero-width matching in regexes

[Python-Dev] Zero-width matching in regexes

MRAB python at mrabarnett.plus.com
Mon Dec 4 18:21:09 EST 2017

  • Previous message (by thread): [Python-Dev] 3.7.0a3 still open
  • Next message (by thread): [Python-Dev] Zero-width matching in regexes
  • Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

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.

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.).

  • Previous message (by thread): [Python-Dev] 3.7.0a3 still open
  • Next message (by thread): [Python-Dev] Zero-width matching in regexes
  • Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

More information about the Python-Dev mailing list
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.