public static string ForEach(this string input, string pattern, PartsF func) { input.Parts(pattern, out string begin, out string search, out string end); while (begin != null && search != null && end != null) { func.Invoke(ref begin, ref search, ref end); //if (Regex.IsMatch(search, pattern)) throw new Exception("Infinite loop Exception."); if (Regex.IsMatch(search, pattern)) { search = search.ForEach(pattern, func); } if (begin + search + end == input) { break; } input = begin + search + end; input.Parts(pattern, out begin, out search, out end); } return(input); }
public static string ForEach(this string input, Regex regex, PartsF partsF) { return(input.ForEach(regex.ToString(), partsF)); }