private StrBuilder replaceImpl(final StrMatcher matcher,final String replaceStr,final int from,int to,int replaceCount){
  if (matcher == null || size == 0) {
    return this;
  }
  final int replaceLen=(replaceStr == null ? 0 : replaceStr.length());
  final char[] buf=buffer;
  for (int i=from; i < to && replaceCount != 0; i++) {
    final int removeLen=matcher.isMatch(buf,i,from,to);
    if (removeLen > 0) {
      replaceImpl(i,i + removeLen,removeLen,replaceStr,replaceLen);
      to=to - removeLen + replaceLen;
      i=i + replaceLen - 1;
      if (replaceCount > 0) {
        replaceCount--;
      }
    }
  }
  return this;
}

private StrBuilder replaceImpl ( final StrMatcher matcher , final String replaceStr , final int from , int to , int replaceCount ) { if ( matcher == null || size == 0 ) { return this ; } final int replaceLen = ( replaceStr == null ? 0 : replaceStr . length ( ) ) ; final char [ ] buf = buffer ; for ( int i = from ; i < to && replaceCount != 0 ; i ++ ) { final int removeLen = matcher . isMatch ( buf , i , from , to ) ; if ( removeLen > 0 ) { replaceImpl ( i , i + removeLen , removeLen , replaceStr , replaceLen ) ; to = to - removeLen + replaceLen ; i = i + replaceLen - 1 ; if ( replaceCount > 0 ) { replaceCount -- ; } } } return this ; }
replaces within the builder using a matcher . < p > matchers can be used to perform advanced behaviour . for example you could write a matcher to delete all occurrences where the character ' a ' is followed by a number .
