正则表达式.*([0-9]{3}\\.[0-9]{2}).*
找到一个匹配在“一些短句111.01”,但未能匹配“一些短句111.01和222.02”我试图懒惰量词中第一次出现“111.01”.*([0-9]{3}\\.[0-9]{2})?.*
或.*([0-9]{3}\\.[0-9]{2}).*?
为无济于事。请帮忙,我需要同时出现这两种情况,这是我的代码。
谢谢
Pattern myPattern = Pattern.compile(".*([0-9]{3}\\.[0-9]{2}).*");
Matcher m = myPattern.matcher(mystring);
while (m.find()) {
String found = m.group(1);
}
您需要删除“。*”。尝试这个:
String mystring = "some short sentence 111.01 & 222.02 ";
Pattern myPattern = Pattern.compile("([0-9]{3}\\.[0-9]{2})");
Matcher m = myPattern.matcher(mystring);
while(m.find()) {
System.out.println("Found value: " + m.group(1) );
}
输出:
实测值:111.01 实测值:222.02
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句