using System; using System.Text.RegularExpressions; using System.IO; public class Test { public static void Main() { var data = "I have this (123) 556-7890 phone number, followed with 123 556 7890, and (123) 556- 7890."; var res = Regex.Replace(data, @"\(?\d{3}\)?-? *\d{3}-? *-?\d{4}", x => Regex.Replace(x.Value, @"\d(?!\d{0,3}$)", "X")); Console.WriteLine(res); } }