I want to remove HTML tags from String. It's easy, I know, I did this:
public String removerTags(String html)
{
return html.replaceAll("\\<(/?[^\\>]+)\\>", " ").replaceAll("\\s+", " ").trim();
}
The problem is that I do not want to delete all tags. I want a tag
<span style=\"background-color: yellow\"> (text) </ span>
will remain unchanged in the line.
I use this as a kind of "highlight" in finding a web application using GWT, which I do ...
And I need to do this because if the search finds text containing some HTML tag (indexing is done by Lucene) and it does not work, appendHTML from safeHTMLBuilder cannot mount the string.
Can you do it pretty well?
Hugs.
source
share