Java Regex String Replace replace(String inputStr, String patternStr, String replacementStr)

Here you can find the source of replace(String inputStr, String patternStr, String replacementStr)

Description

replace

License

Apache License

Declaration

public static String replace(String inputStr, String patternStr, String replacementStr) 

Method Source Code


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

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

public class Main {
    public static String replace(String inputStr, String patternStr, String replacementStr) {
        // Compile regular expression
        Pattern pattern = Pattern.compile(patternStr);

        // Replace all occurrences of pattern in input
        Matcher matcher = pattern.matcher(inputStr);
        String output = matcher.replaceAll(replacementStr);

        return output;
    }//www. j  av  a2s  .  c  om
}

Related

  1. replace(Matcher m, String rv, Object value)
  2. replace(Pattern pattern, String src, Function handler)
  3. replace(String content, String name, String value)
  4. replace(String input, Pattern pattern, Function replacementGenerator)
  5. replace(String input, Pattern regex, Function converter)
  6. replace(String inString, String oldPattern, String newPattern)
  7. replace(String line, String regexp, String replacement)
  8. replace(String message, ResourceBundle bundle)
  9. replace(String operateOn[], String from, String to)