I am adding search functionality to a project. When a search term is entered my program loops through an html string and replaces all occurrences of that word with the search term surrounded by a span tag. the replaceAll() method replaces the words but its not exactly what i want to do. I do not know how to maintain the case of the original word. For example if i search for 'hello': 'Hello' becomes 'hello', 'HELLO' becomes 'hello'. For parsing the html i am using jsoup.

```
Document doc = Jsoup.parse(content);   
Elements elemenets = doc.body().getAllElements();

        for (int i = 1; i < elemenets.size(); i++) {
            String elementText = elemenets.get(i).text();

            if (elementText.toLowerCase().contains(search_term.toLowerCase())) {

                elemenets.get(i).html(elemenets.get(i).html().replaceAll("(?i)" + search_term, "<span id = 'first' style ='background-color:#fbaf5d;'>" + search_term + "</span>"));
            }

        }
String result = doc.toString();

```