JS regular expression to find a substring surrounded by double quotes

Posted by 2619 on Stack Overflow See other posts from Stack Overflow or by 2619
Published on 2013-03-14T07:56:49Z Indexed on 2013/10/22 3:55 UTC
Read the original article Hit count: 110

Filed under:

I need to find a substring surrounded by double quotes, for example, like "test", "te\"st" or "", but not """ neither "\". To achieve this, which is the best way to go for it in the following

1) /".*"/g
2) /"[^"\\]*(?:\\[\S\s][^"\\]*)*"/g
3) /"(?:\\?[\S\s])*?"/g
4) /"([^"\\]*("|\\[\S\s]))+/g

I was asked this question yesterday during an interview, and would like to know the answer for future reference.

© Stack Overflow or respective owner

Related posts about JavaScript