Find and replace String with a substring result
I would go with Regex for this, with greedy matches so that nested results like your example above would only match the outer string.

So with your example here:

Input                       Terms               Output
The search is cool          {sea, search}       The &lt;b&gt;search&lt;/b&gt; is cool


A Regex pattern of search|sea could be derived from the search terms, and only 'search' would be matched. Note that the longest term will need to first for this to work as desired.

String results(String input)
{
 String retVal = input.replaceAll("search|sea", "&lt;b&gt;$1&lt;/b&gt;")

 return input;
}


I think this should be close to what you need, but I havn't had time to test and check. Hope it helps.