1

For example, I have a target string like: str='Every "red","white","blue" flower is $7.'

If I run /Every ("(.+)",?)+ flower is \$(.+)/.exec(str), I will get "red","white","blue" as a whole output element, but what I want is ["red,"white","blue"].

Is there a way to do this, or I can only use split?

Thanks!

Romulus Urakagi Ts'ai
  • 3,699
  • 10
  • 42
  • 68
  • If the double-quotes are balanced, either lookbehind for `"` in a global `.match` while matching non-`"`s, or repeatedly exec `"([^"]+)"` and extract the first group – CertainPerformance Nov 26 '18 at 03:13

1 Answers1

1

A global parameter RegExp and a String.match() solution would be the most practical:

str.match(/"(.*?)"/g) // [ '"red"', '"white"', '"blue"' ]
GMaiolo
  • 4,207
  • 1
  • 21
  • 37