Regex to find any double quoted string within a string
This works also:
var s = "\"some text \"string 1\" and \"another string\" etc\"" ""some text "string 1" and "another string" etc""
s.match(/(?!^)".*?"/g)
Result: [""string 1"", ""another string""]
The negative look ahead will not match the first quote because it's at the beginning, causing all others to match, ignoring the last one, since it doesn't have another quote following. This assumes there won't be any white space before the first quote of course.
Don't escape the "
. And just look for the text between quotes (in non greedy mode .*?
) like:
var string = 'some text "string 1" and "another string" etc';
var pattern = /".*?"/g;
var current;
while(current = pattern.exec(string))
console.log(current);