java正則表達式(.*):不能匹配回車…


 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: }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章