Here is the scenario.
String strText = \"ABC abc Abc aBC abC aBc ABc AbC\";
// Adding a HTML content to this
String searchText = \"abc\";
String strFormatted = s
You can use a backreference. Something like:
String strFormatted = strText.replaceAll(
"(?i)(" + searchText + ")",
"<font color='red'>$1</font>");
I'd like to suggest an alternative using ArrayList
String [] strText = {"ABC", "abc","Abc", "aBC", "abC", "aBc", "ABc", "AbC"};
ArrayList<String> abc = new ArrayList<String> ();
for(int j=0;j<8;j++)
{
if("abc".equalsIgnoreCase(strText[j]))
{
abc.add("<font color='red'>"+strText[j]+"</font>");
}
}
String strFormatted = abc.toString();
System.out.println(strFormatted);