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",")"
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…