I'm trying to grab search terms in a javascript function. I need to output search terms in the following format:
Original:
search term 1,searchte.rm 2abc ,, , searchterm3
Desired Output:
search term 1&searchte.rm 2abc&searchterm3
Basically, I want to "get" the commas and spaces between search terms and convert them to a simple &.
The regex I've tried is /[-'"\w\s.]+/g which gets the actual search terms, not the spaces in between. /[,]+/g gets commas, but I have no idea how to use regex to conditionally get "multiple spaces plus comma" or "multiple commas plus space".
What regexes will make the code above output correctly? Are there any use-cases I'm not thinking of here?