ReplaceAll Method from Matcher : Replace « Regular Expressions « Java

ReplaceAll Method from Matcher

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
  public static void main(String args[]) {
    Pattern p = Pattern.compile("(i|I)ce");
    String candidateString = "ice Ice Ice.";

    Matcher matcher = p.matcher(candidateString);
    String tmp = matcher.replaceAll("Java");



Related examples in the same category

1.REGEX = "a*b"
2.Escaping Special Characters in a Pattern
3.Removing Line Termination Characters from a String
4.Append Replacement Method
5.replaceFirst Method from Matcher
6.Working with Back References
7.Regular Expression search and replace program