I want to recognize integers or decimals and the four simple operations, broken into tokens I can't get the decimal to work, can you please help?
My reg is
expression = "2.7 + 3 * (1 + 2)";
String expRegString = "\d+(\.\d+)*|[\(\)\+\-\*\/]";
Pattern expPattern = Pattern.compile(expRegString);
Matcher expMatcher = expPattern.matcher(expression);
while (expMatcher.find()){
System.out.println(expMatcher.group());
}
gives me "+", "3", "(" , "1", "+" , "2",")"
Edit: the correct result would be "2.7","+", "3", "(" , "1", "+" , "2",")"