Here you can find the source of replaceFirst(String content, String regex, String replacement)
public static String replaceFirst(String content, String regex, String replacement)
//package com.java2s; //License from project: Apache License import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static String replaceFirst(String content, String regex, String replacement) { if (isNone(content)) { return content; }/*from w w w . j av a2s . co m*/ Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(content); if (matcher.find()) { content = matcher.replaceFirst(replacement); } return content; } public static boolean isNone(String str) { if (str == null || "".equals(str)) { return true; } else { return false; } } }