java正则表达式(.*):不能匹配回车…

来源:互联网 发布:java返回值类型有哪些 编辑:程序博客网 时间:2024/06/05 03:47
 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: }
0 0
原创粉丝点击