I have not been able to figure out how to do a multiple split.
For example, given:
str = ‘100 + (xvar*3)’;
strArr = str.split(/^w+|^d+|s+/g);
alert(strArr.join(“n”);
I was expecting to see:
100
+
(
xvar
*
3
)
But instead, I get:
+(xvar*3)
which loses the first number altogether and only removes spaces thereafter.
I also tried:
strArr = str.split(/w+|d+|s+/g);
but the display was even less (lost all words and numbers):
+(
*
)
Two questions:
1. Can I split a string on multiple conditions (words, numbers and symbols)?
2. Is there another, or better, way to do it … or is it impossible with a split?
It is my first step in an attempt at trying to convert a statement from ‘infix’ to ‘postfix’.
I just can’t get past the first step
Thanks for any ideas.