Oct 01

By default regexp matching is case sensitive. To make it case insensitive use the CASE_INSENSITIVE flag in your regex. It can be embedded in the regex string using (?i).


String s = "aBcXYZABCdefAbc";
String replaced = s.replaceAll("(?i)abc", "123"); 

written by objects \\ tags: ,


One Response to “How do I replace all occurences of a string regardless of case?”

  1. Mihir Kale Says:

    Brilliant code! Helped a lot! Thank you!

Leave a Reply