Java Regex String Replace First replaceFirst(StringBuffer buf, StringBuffer aux, Pattern pattern, String replacement, int pos)

Here you can find the source of replaceFirst(StringBuffer buf, StringBuffer aux, Pattern pattern, String replacement, int pos)

Description

replace First

License

Creative Commons License

Declaration

private static boolean replaceFirst(StringBuffer buf, StringBuffer aux, Pattern pattern, String replacement,
            int pos) 

Method Source Code


//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;
    }
}

Related

  1. replaceFirst(final String text, final Pattern regex, final String replacement)
  2. replaceFirst(final String text, final String regex, final String replacement)
  3. replaceFirst(String content, String regex, String replacement)
  4. replaceFirst(String str, String regex, String replacement, int patternFlag)
  5. replaceFirstIgnoreCase(String source, String search, String replace)
  6. replaceFirstOccurrence(String originalText, String oldString, String newString)
  7. replaceFirstStatement(String source, String regex, String statement)
  8. replaceLeading(String string, char replaced, char replacedBy)