Matcher: replaceAll(String text) : Matcher « java.util.regex « Java by API






Matcher: replaceAll(String text)

/*
 * Output:
Original sequence: Java1 Java2 JDK Java2S Java2s.com
Modified sequence: Java Java JDK Java Java2s.com

 * */

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

public class MainClass {
    public static void main(String args[]) { 
      String str = "Java1 Java2 JDK Java2S Java2s.com"; 
   
      Pattern pat = Pattern.compile("Java.*? "); 
      Matcher mat = pat.matcher(str); 
   
      System.out.println("Original sequence: " + str); 
   
      str = mat.replaceAll("Java "); 
   
      System.out.println("Modified sequence: " + str); 
   
    } 
}

           
       








Related examples in the same category

1.Matcher: appendReplacement(StringBuffer sb,String replacement)
2.Matcher.appendTail(StringBuffer sb)
3.Matcher: find()
4.Matcher: group()
5.Matcher: group(int group)
6.Matcher: groupCount()
7.Matcher: lookingAt()
8.Matcher: matches()
9.Matcher: start()