我有一个像java的正则表达式量词
String string = "number0 foobar number1 foofoo number2 bar bar bar bar number3 foobar";
我需要一个正则表达式来给我下面的输出字符串:
number0 foobar
number1 foofoo
number2 bar bar bar bar
number3 foobar
我已经试过
Pattern pattern = Pattern.compile("number\\d+(.*)(number\\d+)?");
Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println(matcher.group());
}
但是这给
number0 foobar number1 foofoo number2 bar bar bar bar number3 foobar
你的字符串中是否有换行符? – 2012-02-09 07:17:53
是的,我不得不添加Pattern.DOTALL,它的工作原理。非常感谢。 – b3bop 2012-02-09 07:23:36