Python: Regex to match multiline C strings -


i'm attempting match multiline c strings via re module.

i'd match strings of form:

char * thestring = "some string \                    want match."; 

i tried following regex, not work:

regex = re.compile(r"\".*\"$", re.multiline) 

i thought match first ", continue searching next line until found closing ", not case. because $ requires there " @ end of line match? there way using regex?

use dot flag.

however, way parse c strings. (?s)"[^"\\]*(?:\\.[^"\\]*)*"

if doesn't support (?s) inline modifier, set modifier in flags parameter.

re.compile(r'"[^"\\]*(?:\\.[^"\\]*)*"', re.dotall)

 (?s)  "  [^"\\]*                       # double quoted text  (?: \\ . [^"\\]* )*  " 

ideally, should add (raw regex) (?<!\\)(?:\\\\)* @ beginning,
make sure opening double quote not escaped.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -