Matcher: replaceAll(String text)
String replaceAll(String replacement)
- Replaces every subsequence of the input sequence that matches the pattern with the replacement string.
/*
* 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);
}
}
Home
Java Book
Essential Classes
Java Book
Essential Classes
Matcher:
- Regular Expression Processing
- Normal character
- Wildcard character
- Using Wildcards and Quantifiers
- Greedy behavior
- Working with Classes of Characters
- Using replaceAll( )
- Using split( )
- Matcher: appendReplacement(StringBuffer sb,String replacement)
- Matcher.appendTail(StringBuffer sb)
- Matcher: find()
- Matcher: group()
- Matcher: group(int group)
- Matcher: groupCount()
- Matcher: lookingAt()
- Matcher: matches()
- Matcher: replaceAll(String text)
- Matcher: start()