Here you can find the source of replace(String text, String findPattern, String replacePattern)
Parameter | Description |
---|
public static String replace(String text, String findPattern, String replacePattern)
//package com.java2s; /*/* www .ja v a 2 s . com*/ * EBI MetaboLights - http://www.ebi.ac.uk/metabolights * Cheminformatics and Metabolism group * * European Bioinformatics Institute (EMBL-EBI), European Molecular Biology Laboratory, Wellcome Trust Genome Campus, Hinxton, Cambridge CB10 1SD, United Kingdom * * Last modified: 9/9/13 4:37 PM * Modified by: conesa * * * ?, EMBL, European Bioinformatics Institute, 2014. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { /** * Replace any text within a text using regular expressions * @param text: Text to search * @param findPattern: Text to find (regular expression) * @param replacePattern: Text to replace (regular expression) * @return */ public static String replace(String text, String findPattern, String replacePattern) { //Create the pattern for the search Pattern pattern = Pattern.compile(findPattern); // Replace all Matcher matcher = pattern.matcher(text); //Return return matcher.replaceAll(replacePattern); } }