I have to write some code in Java which highlights text of a html file displayed in a JTextPane
.
For highlighting I replace "match"
with "<span style=\"background-color: #FFFF00\">match</span>"
and set the whole replaced text in the JTextPane
. Everything works fine! I do this with the help of java.util.regex.Pattern
and java.util.regex.Matcher
.
Now, I determinded a problem: The matcher also matches text within a html tag. For example this line:
<pre><a name="hello-world">Hello World</a></pre>
I need a regex, to create a java.util.regex.Pattern
that only searchs in the String "Hello World".
So, if I want to highlight the matches of "e"
it should looks like
<pre><a name="hello-world">H<span style=\"background-color: #FFFF00\">e</span>llo World</a></pre>
Thank you very much for your help!!