Regex for quoted string with escaping quotes

Regex for quoted string with escaping quotes

Asked on January 8, 2019 in Regex.
Add Comment


  • 2 Answer(s)

    Regex for quoted string with escaping quotes use this:

    /"(?:[^"\\]|\\.)*"/
    

    Above code will Works in The Regex Coach and PCRE Workbench.

    To test in JavaScript use this:

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

    Alternately try this code also Regex for quoted string with escaping quotes:

    /"([^"\\]*(\\.[^"\\]*)*)"/
    
    

    To apply either single quoted or double quoted strings, use below code:

    /"([^"\\]*(\\.[^"\\]*)*)"|\'([^\'\\]*(\\.[^\'\\]*)*)\'/
    
    
    Answered on January 8, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.