I try to resolve this String using a Mathcer: "2+30*4+(5+6)*7"
using this Pattern: "\d*|[()+*-]"
for some reason, the Matcher splits the string correctly, but when going over the splitted strings, it doesn't divide them correctly, leaving empty strings for anything but the digits:
String s = "2+30*4+(5+6)*7";
Pattern p = Pattern.compile("\\d*|[()+*-]");
Matcher m = p.matcher(s);
while (m.find()) {
System.out.print("Start index: " + m.start());
System.out.print(" End index: " + m.end() + " ");
System.out.println("-----> " + m.group());
}
This gives the following output:
Start index: 0 End index: 1 -----> 2
Start index: 1 End index: 1 ----->
Start index: 2 End index: 4 -----> 30
Start index: 4 End index: 4 ----->
Start index: 5 End index: 6 -----> 4
Start index: 6 End index: 6 ----->
Start index: 7 End index: 7 ----->
Start index: 8 End index: 9 -----> 5
Start index: 9 End index: 9 ----->
Start index: 10 End index: 11 -----> 6
Start index: 11 End index: 11 ----->
Start index: 12 End index: 12 ----->
Start index: 13 End index: 14 -----> 7
Start index: 14 End index: 14 ----->
I don't understand why, for example in the second line the end index is 1 (and not 2) resulting an empty string: Start index: 1 End index: 1 ----->
By the way, when I change the pattern's order to "[()+-]|\d" it works fine...

