I'm trying to split an arithmetic equation represented as a String and I want to retain the multi-character delimiters: {==, !=, >=, <=, >, <}
This is what I have:
String expression = "2*(5 +1)- 3 * 2 >= 6^3.1 + 5";
expression = expression.replaceAll("\\s", "");
String[] parsedExpression = expression.split("((?<===)|(?===))|"
+ "((?<=>=)|(?=>=))|"
+ "((?<=!=)|(?=!=))|"
+ "((?<=<=)|(?=<=))|"
+ "((?<=>)|(?=>))|"
+ "((?<=<)|(?=<))");
However it splits it like this:
[2*(5+1)-3*2, >, =, 6^3.1+5]
When the desired split would be this:
[2*(5+1)-3*2, >=, 6^3.1+5]
I'm guessing the problem is that it's my rule for using > and < as a delimiter that's causing the problem but I don't know how to fix it.