Here you can find the source of replaceLeading(String string, char replaced, char replacedBy)
public static String replaceLeading(String string, char replaced, char replacedBy)
//package com.java2s; //License from project: Open Source License import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static String replaceLeading(String string, char replaced, char replacedBy) { Pattern p = Pattern.compile(replaced + "++"); Matcher matcher = p.matcher(string); if (matcher.find()) { string = matcher.replaceFirst(matcher.group(0).replace(replaced, replacedBy)); }/* w w w . ja v a 2s . c o m*/ return string; } public static String replaceLeading(String string, String replaced, String replacedBy) { Pattern p = Pattern.compile("(" + replaced + ")++"); Matcher matcher = p.matcher(string); if (matcher.find()) { string = matcher.replaceFirst(matcher.group(0).replace(replaced, replacedBy)); } return string; } }