title: Text Processing - Detecting if you are inside an HTML tag in Java
body: <p>I have a program that does text processing on a html formatted document based on information on the same document without the html information.   I basically, locate a word or phrase in the unformatted document, then find the corresponding word in the formatted document and alter the appearance of the word or phrase using HTML tags to make it stick out (e.g. bold it or change its color).   </p>
  
  <p>Here is my problem.   Occasionally, I want to do formatting to a word or phrase which might be part of a html tag (for example perhaps I want to do some formatting to the word "font" but only if  is a word that is not inside an html tag).    Is there an easy way to detect whether a string is part of an html tag in a block of text or not?    </p>
  
  <p>By the way, I can't just strip out the html tags in the document and do my processing on the remaining text because I need to preserve the html in the result.   I need to add to the existing html but I need to reliably distinguish between strings that are part of tags and strings that are not.   </p>
  
  <p>Any ideas?</p>
  
  <p>Thank you,</p>
  
  <p>Elliott</p>