Here you can find the source of replace(String string, Pattern[] patterns, String[] replacements)
Parameter | Description |
---|---|
string | The string |
patterns | An array of regular expressions |
replacements | An array of replacement strings (must be the same length and order as patterns) |
public static String replace(String string, Pattern[] patterns, String[] replacements)
//package com.java2s; /**/*from ww w.ja va 2s. c o m*/ * Copyright 2009-2012 Three Crickets LLC. * <p> * The contents of this file are subject to the terms of the LGPL version 3.0: * http://www.gnu.org/copyleft/lesser.html * <p> * Alternatively, you can obtain a royalty free commercial license with less * limitations, transferable or non-transferable, directly from Three Crickets * at http://threecrickets.com/ */ import java.util.regex.Pattern; public class Main { /** * Replaces all occurrences of several regular expressions in order. * * @param string * The string * @param patterns * An array of regular expressions * @param replacements * An array of replacement strings (must be the same length and order * as patterns) * @return The resulting string */ public static String replace(String string, Pattern[] patterns, String[] replacements) { for (int i = 0, length = patterns.length; i < length; i++) string = patterns[i].matcher(string).replaceAll(replacements[i]); return string; } }