Java Regex String Replace All replaceAll(final String regex, final String replaceWith, final String subject)

Here you can find the source of replaceAll(final String regex, final String replaceWith, final String subject)

Description

a method to do a CASE INSENSITIVE regex search-replace

License

Open Source License

Parameter

Parameter Description
regex a parameter
replaceWith a parameter
subject a parameter

Declaration


public static String replaceAll(final String regex, final String replaceWith, final String subject) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    /**//from w ww  . j a  va2s .  co  m
     *  a method to do a CASE INSENSITIVE regex search-replace
     * 
     *  @param regex
     *  @param replaceWith
     *  @param subject
     * 
     */

    public static String replaceAll(final String regex, final String replaceWith, final String subject) {

        final Pattern p = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
        final Matcher m = p.matcher(subject);

        return m.replaceAll(replaceWith);

    }
}

Related

  1. replaceAll(final String regex, final String text, final String replacement)
  2. replaceAll(Pattern p, String s, String r, Function cb)
  3. replaceAll(Pattern pattern, String string, String replacement)
  4. replaceAll(String original, String regexWhat, String with)