Hi
First off apologies if this question is in the wrong place... There is no dedicated RegEx forum and since I'm working in JS and in my experience RegEx is most commonly used in JS - here lies my problem
I have a number of search strings that I would like to split into an array. The search is usually separated by spaces, but the search terms can also contain spaces and in this case they are quoted. Here's an example:
SearchTerm1=foo SearchTerm2=bar SearchTerm3="hello world" SearchTerm4="nospacesbutquotedanyway" SearchTerm5=foo,bar
I would like to return as an array:
[0][0]SearchTerm1
[0][1]foo
[1][0]SearchTerm2
[1][1]bar
[2][0]SearchTerm3
[2][1]hello world
[3][0]SearchTerm4
[3][1]nospacesbutquotedanyway
[4][0]SearchTerm5
[4][1]foo,bar
I'm toying with writing a function that first searches the string for quoted chunks, perhaps replacing the spaces inside quotes with an uncommon character in order to split the string by space and replace them back again afterwards. But hoping someone might come up with a magic RegEx to neatly do the job for me!
Thanks in advance,
~S~
First off apologies if this question is in the wrong place... There is no dedicated RegEx forum and since I'm working in JS and in my experience RegEx is most commonly used in JS - here lies my problem
I have a number of search strings that I would like to split into an array. The search is usually separated by spaces, but the search terms can also contain spaces and in this case they are quoted. Here's an example:
SearchTerm1=foo SearchTerm2=bar SearchTerm3="hello world" SearchTerm4="nospacesbutquotedanyway" SearchTerm5=foo,bar
I would like to return as an array:
[0][0]SearchTerm1
[0][1]foo
[1][0]SearchTerm2
[1][1]bar
[2][0]SearchTerm3
[2][1]hello world
[3][0]SearchTerm4
[3][1]nospacesbutquotedanyway
[4][0]SearchTerm5
[4][1]foo,bar
I'm toying with writing a function that first searches the string for quoted chunks, perhaps replacing the spaces inside quotes with an uncommon character in order to split the string by space and replace them back again afterwards. But hoping someone might come up with a magic RegEx to neatly do the job for me!
Thanks in advance,
~S~