String (String textToMarkup, Pattern insideHtmlTagPattern, String option, Color textColor, Color backgroundColor) { StringBuilder result = new StringBuilder(); int beg = 0; int idx; while ((idx = Strings.indexOfIgnoreCase(textToMarkup, option, beg)) != -1) { final String prefix = textToMarkup.substring(beg, idx); final String toMark = textToMarkup.substring(idx, idx + option.length()); if (insideHtmlTagPattern.matcher(prefix).matches()) { final int lastIdx = textToMarkup.indexOf(">", idx); result.append(prefix).append(textToMarkup, idx, lastIdx + 1); beg = lastIdx + 1; } else { result.append(prefix) .append("<font color='#").append(ColorUtil.toHex(textColor)).append("' bgColor='#").append(ColorUtil.toHex(backgroundColor)).append("'>") .append(toMark).append("</font>"); beg = idx + option.length(); } } result.append(textToMarkup.substring(beg)); return result.toString(); }