I would like to parse the following string:
this OR (this AND (this OR (that AND this))) OR this
Into this:
[
"this",
"OR",
[
"this",
"AND",
[
"this",
"OR",
[
"that",
"AND",
"this"
]
]
],
"OR",
"this"
]
However, I also need to support things like "this is a text" OR this which parses as ["this is a text", "OR", "this"] where the quotes represent the whole string which cancels the space-breaking between words.
But this is not an issue since it's not recursive like brackets. This can be done with regex.
After some research, this can not be done with ES regex, but it can be done with PHP's regex. Is there a way to do it with JavaScript's regex? If not, what are the best alternatives to use, maybe a prebuilt library for this?
(\(([^()]|(?R))*\)). As you see it usesSubroutine token, it is not supported in other languages. But if you do know how to solve this like the PHP regex but in javascript, that'd solve all of my issues because I can recursively run the regex(["'])(?:(?=(\\?))\2.)*?\1