Description:
In my Javascript code I have a logical expression as a string, like in the example below:
'foo && !bar || baz'
Where foo, bar and baz are the names of some tags within my app.
A tag can contain lowercase, uppercase letters, numbers and special characters (+, - , *, #, etc). So the following strings may be valid tags:
foo-bar, foo#, f*oo.
The possible logical operators are: || (OR), && (AND) and ! (NOT).
Requirement:
I need to get only the tags from the string above, as an array:
['foo', 'bar', 'baz']
The code I've tried:
I tried to use the regex /&&|\|/ to get the logical operators, and then try to invert the logical expression, but without success.
Other examples:
foo && bar => expected result ['foo', 'bar']
foo1 || bar1 => expected result ['foo1', 'bar1']
foo+ && !bar& => expected result ['foo+', 'bar&']
foo && bar || baz => expected result ['foo', 'bar', 'baz']