Here you can find the source of replaceFirstIgnoreCase(String source, String search, String replace)
public static String replaceFirstIgnoreCase(String source, String search, String replace)
//package com.java2s; /*//from w w w .j a v a 2s. 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 replaceFirstIgnoreCase(String source, String search, String replace) { source = (source == null) ? "" : source; if (search == null) { return source; } replace = replace == null ? "" : replace; StringBuilder strBuilder = new StringBuilder(); strBuilder.append("((?i)"); strBuilder.append(Pattern.quote(search)); strBuilder.append(")"); return Pattern.compile(strBuilder.toString()).matcher(source).replaceFirst(replace); } public static String replaceFirst(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).replaceFirst(replace); } }