How can I perform case-insensitive pattern search and case-preserving replacement?

前端 未结 2 763
梦毁少年i
梦毁少年i 2021-01-21 18:44

Here is the scenario.

String strText = \"ABC abc Abc aBC abC aBc ABc AbC\";
// Adding a HTML content to this
String searchText = \"abc\";
String strFormatted = s         


        
2条回答
  •  Happy的楠姐
    2021-01-21 19:25

    You can use a backreference. Something like:

    String strFormatted = strText.replaceAll(
        "(?i)(" + searchText + ")", 
        "$1");
    

提交回复
热议问题