Similar to other responses, but also different. Accepts the .co.uk addresses too.
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
public class Test
{
public static void Main()
{
String regex = @"(.{2}).+@.+(.{2}(?:\..{2,3}){1,2})";
String replace = "$1*@*$2";
List<String> tests = new List<String>(new String[]{
"joe@example.com",
"jim@bob.com",
"susie.snowflake@heretoday.co.uk",
"j@b.us",
"bc@nh.us"
});
tests.ForEach(email =>
{
Console.WriteLine(Regex.Replace(email, regex, replace));
});
}
}
Results in:
jo*@*le.com
ji*@*ob.com
su*@*co.uk
j@b.us
bc@nh.us
Though I'm not 100% sure what you want to do with names that only have 2 letters on either side (thus the last two results). But that's my bid. Example