【发布时间】:2012-01-19 18:16:23
【问题描述】:
我有下一个代码:
public static void createTokens(){
String test = "test is a word word word word big small";
Matcher mtch = Pattern.compile("test is a (\\s*.+?\\s*) word (\\s*.+?\\s*)").matcher(test);
while (mtch.find()){
for (int i = 1; i <= mtch.groupCount(); i++){
System.out.println(mtch.group(i));
}
}
}
还有下一个输出:
word
w
但在我看来一定是:
word
word
有人请解释一下为什么会这样?
【问题讨论】:
标签: java regex non-greedy