This suggests that quests are well balanced - you have an even number of quests, not quests in the middle of words.
You can match for /"([^"]+)"|(\S+)/ - this will result in your words being quoted strings or non-spaces. He fixed the word in group 1 or 2 and you can join get results with delimiter & .
Another option: you can get it in a single replacement, thanks to which it is very similar to the first template, skipping your tokens. Here is a javascript example:
s = s.replace(/(?:"([^"]+)"|(\S+))\s*/g, '$1$2&');
(note that you will have an extra ampersand at the end of the line)
source share