ok, I guess the code says it all.
//I have this string.
var str = '"Watch out" "for the" "rock!"'
//this is one of the many patterns that I tried
res=str.match(/"(.*)" "(.*)" "(.*)"/g)
I want an array like: res=["Watch out","for the","rock!"]
How can I do that?
Like this:
You need to remove the
gflag because with that flag you will get a list of matches and not the list of groups for a single match. Also, you should specify your groups as non-greedy (quantifier*?), otherwise they might match too much. Finally, remove the first entry from the array usingres.shift()– the first entry is the entire matched string and you want only the groups.