Regular expression and substitution, unexpected duplication

Laurent Pointal laurent.pointal at
Wed Aug 19 18:32:57 CEST 2015

MRAB wrote:

> On 2015-08-18 22:42, Laurent Pointal wrote:
>> Hello,
>> ellipfind_re = re.compile(r"((?=\.\.\.)|…)", re.IGNORECASE|re.VERBOSE)
>> ellipfind_re.sub(' ... ',
>>         "C'est un essai... avec différents caractères… pour voir.")

> (?=...) is a lookahead; a non-capture group is (?:...).
> The regex should be r"((?:\.\.\.)|…)", which can be simplified to just
> r"\.\.\.|…" for your use-case. (You don't need the
> re.IGNORECASE|re.VERBOSE either!)


I made same mistake in another place, but dont see it here.


More information about the Python-list mailing list