Skip to content Skip to sidebar Skip to footer

Javascript Match All Regex That Returns An Array Of All Phrases Wrapped In Double Quotes

I have a string something like ''this one' and 'that one''. I want to return an array of all double quoted strings i.e. [this one, that one]. So far I've tried: var mystring = ''t

Solution 1:

I think you are missing the (g)lobal modifier:

var mystring = '"this one" and "that one"';
var m = mystring.match(/"(.*?)"/g);
console.log(m);

update

var mystring = '"this one" and "that one"';
var m = mystring.match(/"(.*?)"/g).map(function(n){ return n.replace(/"/g,'')});
console.log(m);

Post a Comment for "Javascript Match All Regex That Returns An Array Of All Phrases Wrapped In Double Quotes"