using System; using System.Linq; using System.Text.RegularExpressions; public class Test { public static void Main() { var s = "#Abc=\"\""; var result = Regex.Replace(s, "#[A-Za-z0-9]+(=\"\")", m=> string.Format("{0}{1}{2}", m.Value.Substring(0, m.Groups[1].Index), new string('?', m.Groups[1].Length), m.Value.Substring(m.Groups[1].Index+m.Groups[1].Length, m.Value.Length-m.Groups[1].Index-m.Groups[1].Length))); Console.WriteLine(result); } }