我想识别整数或小数以及四个简单的操作,分成标记我无法让小数工作,你能帮忙吗?
我的注册是
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());
}
给我"+", "3", "(" , "1", "+" , "2",")"
编辑:正确的结果是"2.7","+", "3", "(" , "1", "+" , "2",")"