c++ - Python RE - Regular expression for matching a printf-like format string with escaped quotation marks -


I am writing a small + preprocessor in Python, which should have format strings like printf. I need a regular expression, which corresponds to other quote marks in the first place, but ('' '' ') is ignoring all the escape marks. Here is an example:

  foo bar, "value \" s \ ":% s", "foobar");  

I need a regex for this:

  "value \":  

I have so far:

  (". *?")  

But I could not find any way to avoid quotation marks I'm so grateful if someone can give me a solution / tip.

Thank you in advance!

You can try regex below to match the first of all the characters Hala and the other ",

  \". *] [^ \\] \ " 

< Previous> & gt; & Gt; & Gt; S = r'foo (bar, "value \" s \ ":% s", "foobar"); '& Gt; & Gt; & Gt; M = re.search (r '". *? [^ \\]"', s)> gt; & Gt; & Gt; Results = m.group (0)> gt; & Gt; & Gt; Print result "value \" s \ ":% s"

Explanation:

  • "< / Code> matches the first double quote marks.
  • . *? Any characters match zero or more times. ? After * matches an unwillingness. << Li> matches << code> " (Double quote) symbol

Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -