/// <summary> /// Within a specified input string, replaces all groups with the specified number that match the regular expression with a string where each character is replaced with the specified character. /// </summary> /// <param name="regex">The regular expression to be matched.</param> /// <param name="input">The string to search for a match.</param> /// <param name="replacementChar">The replacement char.</param> /// <param name="groupNumber">A number of the group.</param> /// <exception cref="ArgumentNullException"><paramref name="regex"/> or <paramref name="input"/> is <c>null</c>.</exception> public static string ReplaceGroupChar(this Regex regex, string input, char replacementChar, int groupNumber) { if (regex == null) { throw new ArgumentNullException(nameof(regex)); } if (input == null) { throw new ArgumentNullException(nameof(input)); } return(RegexReplace.ReplaceGroups(regex, input, groupNumber, group => new string(replacementChar, group.Length))); }