1: public static void main(String[] args) {
2: String regex1="a((.||(\r\n))*)b";
3: //如果是regex1="a(.*)b";不能匹配str,因为API文档中说"."匹配
4: //Any character (may or may not match line terminators)
5: //其中Line terminators包括/r,/n,/r/n三种。
6: String regex2="a(.*?)b";
7: String str = "kjljakjlj\r\nijdsklfjb";
8:
9: Pattern info = Pattern.compile(regex1);
10: Matcher matcher = info.matcher(str);
11: while(matcher.find()){
12: System.out.println( matcher.group(1));
13:
14: }