Java Regex String Replace replace(String source, String search, String replace)

Here you can find the source of replace(String source, String search, String replace)

Description

replace

License

LGPL

Declaration

public static String replace(String source, String search, String replace) 

Method Source Code

//package com.java2s;
/*//w w w. j a  v  a2 s.  c  o  m
 * MoXie (SysTem128@GMail.Com) 2009-3-11 10:06:36
 * 
 * Copyright © 2008-2009 Zoeey.Org
 * Code license: GNU Lesser General Public License Version 3
 * http://www.gnu.org/licenses/lgpl-3.0.txt
 */

import java.util.regex.Pattern;

public class Main {

    public static String replace(String source, String search, String replace) {
        source = (source == null) ? "" : source;
        if (search == null) {
            return source;
        }
        replace = replace == null ? "" : replace;
        return Pattern.compile(Pattern.quote(search)).matcher(source).replaceAll(replace);
    }
}

Related

  1. replace(String pattern, String replace, String s)
  2. replace(String s, Pattern pattern, Function func)
  3. replace(String s, Properties p)
  4. replace(String s1, String s2, Pattern pattern)
  5. replace(String source, String prefix, String suffix, String prefixReplace, String suffixReplace)
  6. replace(String source, String search, String replacement)
  7. replace(String source, String[] patterns, String[] replacements)
  8. replace(String str, String key, String value)
  9. replace(String str, String replacement, Function func)