using System; using System.IO; using System.Text.RegularExpressions; public class Test { public static void Main() { var str = " modif-i-ed a-im"; var res = Regex.Replace(str, @"-?\b([a-zA-Z])\b-", "y"); Console.WriteLine(res); } }