using System; using System.Text.RegularExpressions; public class Test { public static void Main() { string[] strings = { "File name without 3 digit end.jpg", "username1@example.com", "username@example.com", "username1@example@example.com", "username1@", "test", }; String pattern = @"\G([^\s@])[^\s@](?=[^\s@]*@[^\s@]+(?!\S))"; Regex regex = new Regex(pattern); string substitution = @"$1*"; foreach(string str in strings) { Console.WriteLine(regex.Replace(str, substitution)); } } }