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());