Java regex string replace example (case insensitive)
November 11, 2011 13:59:46 Last update: November 11, 2011 13:59:46
This is an example to replace a Java string with case insensitive match.
Code:
Output:
Code:
public class ReplaceTest { public static void main(String[] args) { String s = "Test TEST tEst tESt Test"; System.out.println(s.replaceFirst("Test", "Done")); System.out.println(s.replaceFirst("test", "Done")); System.out.println(s.replaceFirst("(?i)test", "Done")); System.out.println(s.replaceAll("(?i)test", "Done")); } }
Output:
Done TEST tEst tESt Test Test TEST tEst tESt Test Done TEST tEst tESt Test Done Done Done Done Done