Regex for quoted string with escaping quotes

Andrii Kasian picture Andrii Kasian · Oct 30, 2008 · Viewed 167.5k times · Source

How do I get the substring " It's big \"problem " using a regular expression?

s = ' function(){  return " It\'s big \"problem  ";  }';     

Answer

PhiLho picture PhiLho · Oct 30, 2008
/"(?:[^"\\]|\\.)*"/

Works in The Regex Coach and PCRE Workbench.

Example of test in JavaScript:

    var s = ' function(){ return " Is big \\"problem\\", \\no? "; }';
    var m = s.match(/"(?:[^"\\]|\\.)*"/);
    if (m != null)
        alert(m);