[issue29977] re.sub stalls forever on an unmatched non-greedy case

Matthew Barnett report at bugs.python.org
Tue Apr 4 16:49:12 EDT 2017


Matthew Barnett added the comment:

A slightly shorter form:

    /\*(?:(?!\*/).)*\*/

Basically it's:

    match start

    while not match end:
        consume character

    match end

If the "match end" is a single character, you can use a negated character set, for example:

    [^\n]*

otherwise you need a negative lookahead, for example:

    (?:(?!\r\n).)*

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29977>
_______________________________________


More information about the Python-bugs-list mailing list