關於替換忽略大小寫的問題


import   java.util.regex.*; 

String   str= "J2EE學習筆記J2ee   and   j2ee "; 
String   search= "j2ee "; 

Pattern   p   =   Pattern.compile(search,   Pattern.CASE_INSENSITIVE); 
Matcher   m   =   p.matcher(str); 

StringBuffer   sb   =   new   StringBuffer(); 
while   (m.find()) 
{ 
        m.appendReplacement(sb,   " <font   color=\ "red\ "> "+str.substring(m.start(),   m.end())+ " </font> "); 
} 

m.appendTail(sb); 
System.out.println(sb.toString());
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章