'java String, replaceall() but keep case in original string

hello i make a program that can highlight strings into a webview(android) and i stuck at replacing string with colored one, with this piece of code

        String[] arr = "LION SAVANA".split(" ");//i split textview string to have words (here we suppose that user entered : "lion savana"


        String finalText = "the lion is a species of mamifer living into the savana"

        for (String ss : arr) {
            if (ss.length() > 2) {
                 ss = ss.replace("*","");
                finalText = finalText.replaceAll("(?i)" + ss, "<b style = \"color:#2575ff\";>" + ss + "</b>");//finally here i replace all lion or savana occurrences by blue ones -> but i not keeps case :(
            }
        }

after this loop the text will be "the LION is a species of mamifer living into the SAVANA" ,colored in blue like expected but with uppercase as i don't expect



Solution 1:[1]

ok i've found how to doit, here

so finally, i just replaced this line :

finalText = finalText.replaceAll("(?i)" + ss, "<b style = \"color:#2575ff\";>" + ss + "</b>");

by

finalText = finalText.replaceAll("(?i)" + ss, "<b style = \"color:#2575ff\";>" +"$0" + "</b>");

$0 apparently is the word that i want to keep with the same case

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community