Matcher.appendTail(StringBuffer sb)
StringBuffer appendTail(StringBuffer sb)
- Implements a terminal append-and-replace step.
/*
goat goats
*/
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class MainClass {
public static void main(String[] av) {
String joke = "dog " + "dogs";
String regEx = "dog";
Pattern doggone = Pattern.compile(regEx);
Matcher m = doggone.matcher(joke);
StringBuffer newJoke = new StringBuffer();
while (m.find()) {
m.appendReplacement(newJoke, "goat");
}
m.appendTail(newJoke);
System.out.println(newJoke.toString());
}
}
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()