替換string中的部分字符串 關鍵時候還得正則出馬。。。。

String startRegex = "(<|<f|<fo|<fon|<font|<font |<font c|<font co|<font col|<font colo|<font color|<font color=|<font color='|<font color='r|<font color='re|<font color='red|<font color='red'|<font color='red'>|<font color='red'>)$";
       Pattern pat = Pattern.compile(startRegex); 
       Matcher matcher = pat.matcher(content);    
       while (matcher.find()) {
            content = content.replaceAll(startRegex, "");
       } 
       
       String endRegex = "(</f|</fo|</fon|</font)$";
       Pattern pat1 = Pattern.compile(endRegex); 
       Matcher matcher1 = pat1.matcher(content);    
       while (matcher1.find()) {
            content = content.replaceAll(endRegex, "</font>");
       }
       
       String regex = "(<font color='red'>.*)$";
       Pattern pat2 = Pattern.compile(regex); 
       Matcher matcher2 = pat2.matcher(content);    
       while (matcher2.find()) {
            content = content + "</font>";
       }spa

相關文章
相關標籤/搜索