Can someone assist me in precisely breaking down the expression
-(ab | c) & d -> (d|c)&e <-> f
into individual elements within an array?
['-', '(', 'ab', '|', 'c', ')', '&', 'd', '->', '(', 'd', '|', 'c', ')', '&', 'e', '<->', 'f']
I require the string to be divided into tokens, where a combination of letters like ab
should be treated as one token. The operators I have include -
, (
, )
, |
, &
, ->
, and <->
.
An approach might resemble
var str = '-(ab | c) & d -> (d|c)&e <-> f';
var regex = /([-&\|()]|\w+)/;
str.split(regex);
However, this method does not account for ->
and <->