Matcher.appendTail(StringBuffer sb) : Matcher « java.util.regex « Java by API






Matcher.appendTail(StringBuffer sb)

/*
 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());
  }

}

           
       








Related examples in the same category

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