import java.util.regex.*;
public class Regex2 {
public static void main(String[] args) {
Pattern p = Pattern.compile("\\d*");
Matcher m = p.matcher("ab34ef");
boolean b = false;
while ( m.find()) {
System.out.print(m.start() + m.group());
}
}
}此代码产生输出的原因: 01234456
发布于 2015-01-03 14:43:37
\d* means integer 0 or more times.So an empty string between a and b ,before a ...those are also
matched.Use `\d+` to get correct result.见演示。
发布于 2015-01-03 15:20:17
因为\\d*表示零或更多位数。
作为,

https://stackoverflow.com/questions/27755980
复制相似问题