Ron wrote: > This is probably a repeated question, but try as I might I was unable > to find something similar in the archives. > > I'm trying to develop a regular expression for recognizing a simplified > C-Style string syntax. I need it to be able to handle escape sequences > of the form \x where x is any character including ". > > Here's what I'm trying: > > \"([^"\\]|(\\.))*\" > > When I try to get it to recognize something like: > > "I said, \"Hello!\"" > > It stops at the first quote after the \.
Works for me: >>> print re.search(r'\"([^"\\]|(\\.))*\"', ... r'"I said \"Hello!\""').group(0) "I said \"Hello!\"" You can leave out the backslashes in fron of the first and last quotes in the regex, by the way, at least if you use ' instead of " to delimite it: >>> print re.search(r'"([^"\\]|(\\.))*"', ... r'"I said \"Hello!\""').group(0) "I said \"Hello!\"" -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven -- http://mail.python.org/mailman/listinfo/python-list