[Python-Dev] Re: re.split on empty patterns

Mike Coleman mkc at mathdogs.com
Wed Aug 11 03:29:32 CEST 2004


"Fredrik Lundh" <fredrik at pythonware.com> writes:
> the RE module already have an established method for specifying flags,
> either with (?x) markers in the pattern strings, or via the "flags" argument
> to re.compile and others.
> 
> any reason why you cannot use a new standard flag for this purpose?
> 
> (e.g. (?e) and re.EMPTY_OK)

I considered this when I was writing the patch, but it seemed like the
"(?x)"-style flags all have to do with the meaning and interpretation of the
pattern.  They're quite general and make sense for all of the methods that use
patterns.

The "empty okay" concept, on the other hand, seems to have to do specifically
with how re.split uses the pattern.  That is, in the process of finding
matches decides (or not) to discard the empty matches.  Would you even want
the other methods to have this "do what I say but also discard empty matches"
wart?  IMO, the only reason for the existence of the option is to preserve
backward compatibility with previous code that assumes empties will be
discarded.  This is something we want to go away eventually, IMO.

> for extra credit, add EMPTY_OK behaviour to find, finditer, and sub/subn.

I'd vote -1, since there's no backward compatibility issue for these.  If
someone writing new code doesn't want to match empty strings, they can easily
write a pattern that doesn't match empty strings.

Mike



More information about the Python-Dev mailing list