Re: regex to match python string literal syntax

2010-02-10 Thread Ken Seehart
Found this in pypy! # Match any flavor of string; /*the terminating quote is optional*/ # so that we're robust in the face of incomplete program text. _match_stringre = re.compile(r""" \""" [^"\\]* (?: (?: \\. | "(?!"") ) [^"\\]* )* (

regex to match python string literal syntax

2010-02-10 Thread Ken Seehart
I found this: http://code.activestate.com/recipes/475109/ But it is incorrect in some cases, such as: * "foo \" bar"* / (incorrectly matches "foo \")/ * '''* /(incorrectly matches the second two single quotes)/ *" foo bar "* / (incorrectly matches quote containing newline/) Anyone kno