I have a String = A+B+CC-D0. I want to use a regular expression to split it apart to get an array of of the ops {+,+,-}
I have tried the regular expression:
"[^+-]"
But the output gave me a array of { ,+,+, ,+}, why?
String s1 = "A+B+C-D";
String s2 = "A0+B0";
String[] op1 = s1.split([^+-]);
String[] op2 = s2.split([^+-]);
for(int i = 0; op1.length; i++){
System.out.println(op1[i]);
}
Here's the output:
Output of op1:
""
"+"
"+"
""
"-"
Output of op2:
""
""
"+"