Monday, March 23, 2009

How do I replace all occurences of a string regardless of case?

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");

No comments: