Search code examples
c#regexregex-group.net-standard-2.0

c# regex to capture everything between 2 double-quotes, escaped double-quote included


I am getting trouble writing a regex in C# that basically captures everything between 2 double quotes. If that group contains escaped double-quote, they would be captured as well. After reading the regex wiki I still haven't been able to write one that completely does the job.

There is a coma character between the different matches.

The following string:

 "first \"value\\\\", "second, value", "third value"

needs to give the following matches:

  • first \"value\\\\
  • second, value
  • third value

Thanks for your help!


Solution

  • This regex should solve your purpose -

    str = Regex.Replace(str, @"(""[^""\\]*(?:\\.[^""\\]*)*"")|", "$1");