Here you can find the source of replaceFirst(StringBuffer buf, StringBuffer aux, Pattern pattern, String replacement, int pos)
private static boolean replaceFirst(StringBuffer buf, StringBuffer aux, Pattern pattern, String replacement, int pos)
//package com.java2s; /*/*from www . j ava 2 s . c om*/ * Written by Dawid Kurzyniec and released to the public domain, as explained * at http://creativecommons.org/licenses/publicdomain */ import java.util.regex.*; public class Main { private static boolean replaceFirst(StringBuffer buf, StringBuffer aux, Pattern pattern, String replacement, int pos) { boolean chg = false; aux.setLength(0); Matcher matcher = pattern.matcher(buf); if (matcher.find(pos)) { matcher.appendReplacement(aux, replacement); chg = true; } matcher.appendTail(aux); buf.setLength(0); buf.append(aux); return chg; } }