由于您的模式是非贪婪的,因此它们在仍由匹配项组成的情况下,匹配的文本越少越好。
去除 ?在第二组中,您会得到
单词
word word big small
Matcher mtch = Pattern.compile("test is a (\s*.+?\s*) word (\s*.+\s*)").matcher(test);
由于您的模式是非贪婪的,因此它们在仍由匹配项组成的情况下,匹配的文本越少越好。
去除 ?在第二组中,您会得到
单词
word word big small
Matcher mtch = Pattern.compile("test is a (\s*.+?\s*) word (\s*.+\s*)").matcher(test);