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: ,


2 Responses to “How do I replace all occurences of a string regardless of case?”

  1. Mihir Kale Says:

    Brilliant code! Helped a lot! Thank you!

  2. Nagabhushan Says:

    Nice very helpful

Leave a Reply

You must be logged in to post a comment.