I have a search app that searches local HTML files for a specified
term. I then display the pages that contain the term.
I would like to highlight the search term within the HTML when it is
viewed.
I have the following regular expression code:
string searchTerm = "(?<STARTTAG>(<[^>]*>.*))(?<MATCHTERM>(" +
lastSearchTerm + "))(?<ENDTAG>(.*<[^>]*>))";
string replaceString = "${STARTTAG}<span
style=\"background-color:#FFFFCC\">${MATCHTERM}</span>${ENDTAG}";
Regex.Replace(htmlBody, searchTerm, replaceString,
RegexOptions.IgnoreCase);
I am trying to match the search term within HTML tags. i.e.
<htmltag>searchterm</htmltag>
and then replace the search term with a span tag to color it, like so:
<htmltag><span
style=\"background-color:#FFFFCC\">searchterm</span></htmltag>
This works, but works inconsitently (and without a discernable pattern
when it fails).
So, does anyone see anything obviously wrong with my Regular
Expressions? I am pretty new to regular expressions, although I
usually know enough to get stuff done.
mike c