Regular expression and substitution, unexpected duplication

Laurent Pointal laurent.pointal at free.fr
Wed Aug 19 12:32:57 EDT 2015


MRAB wrote:

> On 2015-08-18 22:42, Laurent Pointal wrote:
>> Hello,
<zip>
>> 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!)

Thanks,

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

A+
Laurent.





More information about the Python-list mailing list