I've got an expression held in a JS string and I want to split it into tokens. The string could contain any symbols or characters (its actually a string expression)
I've been using
expr.split(/([^\"]\S*|\".+?\")\s*/)
But when I get a text symbol outside of quotes it splits it wrongly.
e.g. When
expr = "Tree = \"\" Or Tree = \"hello cruel world\" + \" and xyz\""
Then The OR gets mixed in with the following string.
Splitting on \b seems to be the way to go (is it?) but I don't know how to keep the strings in quotes together. So ideally in the above I'd get:
Tree
=
\"\"
Or
Tree
=
\"Hello cruel world\"
+
\" and xyz\"
I suppose ideally I would find a tokenizer but if I could do it in regex that would be a major headache solved :)
thanks
+means at least 1 character, so it will never match"". Try a*.\bwon't solve your problem here if you want to retrieve the=as a match : since=isn't a word character, there won't be any word-boundary around it.