Java Regex String Replace First replaceFirstStatement(String source, String regex, String statement)

Here you can find the source of replaceFirstStatement(String source, String regex, String statement)

Description

replace First Statement

License

Apache License

Parameter

Parameter Description
source a parameter
regex a parameter
statement a parameter

Declaration

public static String replaceFirstStatement(String source, String regex, String statement) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    /**/*from  w  w w .ja v  a2  s.  co  m*/
     *
     * @param source
     * @param regex
     * @param statement
     * @return
     */
    public static String replaceFirstStatement(String source, String regex, String statement) {
        Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern == null ? null : pattern.matcher(source);
        return matcher == null ? null : matcher.replaceFirst(statement);
    }
}

Related

  1. replaceFirst(String content, String regex, String replacement)
  2. replaceFirst(String str, String regex, String replacement, int patternFlag)
  3. replaceFirst(StringBuffer buf, StringBuffer aux, Pattern pattern, String replacement, int pos)
  4. replaceFirstIgnoreCase(String source, String search, String replace)
  5. replaceFirstOccurrence(String originalText, String oldString, String newString)
  6. replaceLeading(String string, char replaced, char replacedBy)