0

I have this right now:

"arcade racing games".match(/\b(?:arcade racing|arcade|racing)\b/ig)

which gives me this result: ["arcade racing"]

I want it to give me this result instead: ["arcade racing", "arcade", "racing"]

Is there a way for me to do this with 1 regex search, without using a loop or high level functions like map or filter?

tremonti92
  • 13
  • 1
  • 4
  • You can use capture groups, which you would access with different indexes. Try this: `/\b(arcade) (racing|arcade)\b/ig` – Keldan Chapman Dec 17 '20 at 08:31
  • @KeldanChapman That won't work. Regex in JavaScript always tests a position only once. There can be no multple matches at the same location in the string. This can't be solved with a single regex here. There is a regex solution only in Raku regex. – Wiktor Stribiżew Dec 17 '20 at 08:32
  • @WiktorStribiżew True, matchAll wouldn't work, but capture groups would. – Keldan Chapman Dec 17 '20 at 08:33

0 Answers0