Hi, I came across a problem related to regular expressions which I cannot solve.
I need to tokenize the request (split the request into parts), suppose, as an example:
These are the separate query elements "These are compound composite terms"
Ultimately, I need to have an array of 7 tokens:
1) These 2) are 3) the 4) separate 5) query 6) elements 7) These are compound composite term
The seventh token consists of a few words because it was inside double quotes.
My question is: is it possible to tokenize the input string according to the above explanations using one regex ?
Edit
I was curious about being able to use Regex.exec or similar code instead of split when achieving the same, so I did some investigation, followed by another question here . And since another answer to the question, you can use the following regular expression:
(?:")(?:\w+\W*)+(?:")|\w+
When using the following scenario using a single liner:
var tokens = query.match(/(?:")(?:\w+\W*)+(?:")|\w+/g);
Hope this will be helpful ...
Lu4 source share