Why this regex for string literals can't handle escaped quotes?.... '"(\\.|[^"])*"'

cseberino at gmail.com cseberino at gmail.com
Thu Aug 9 11:30:56 EDT 2018


Why this regex for string literals 
can't handle escaped quotes?.... '"(\\.|[^"])*"'

See this...

>>> string_re = '"(\\.|[^"])*"'

>>> re.match(string_re, '"aaaa"')
<_sre.SRE_Match object; span=(0, 6), match='"aaaa"'>

>>> re.match(string_re, '"aa\"aa"')
<_sre.SRE_Match object; span=(0, 4), match='"aa"'>

How make the last match be the entire string '"aa\"aa"' ?

cs



More information about the Python-list mailing list