I have a
string text which is nothing but html codes. I need to search words in the string and highlight them before rendering as a html page. I have the following code .
Pattern p = Pattern.compile(keyword, Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(text);
while (m.find()) {
String beforeReplacement = m.group();
m.appendReplacement(sb, "<b><span style='background-color:yellow'>" + beforeReplacement + "</span></b>");
}
m.appendTail(sb);
It was working fine until recently I found a bug . The thing is if the
word to be search (say class) is a part of html tag as well (for e.g. <x class="abc"> here is the class </x>), then both the tag and text gets highlighted.
How can I make pattern match ignoring the words inside html element tags?
I think it is using proper regex . But I am not able to come up with one ...
Any help...
sarad