// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Text.RegularExpressions; namespace E { public static class MyExtensions { private static readonly Regex re = new Regex(@"\b(\w+(\.\w+)*)@(\w+\.\w+(\.\w+)*)\b", RegexOptions.Compiled); public static String Obfuscate(this String s) { string res = s; foreach(Match m in re.Matches(s)) { res = res.Replace(m.Groups[0].Value, m.Groups[1].Value + " AT " + m.Groups[3].Value.Replace(".", " DOT ")); } return res; } } public class Program { public static void Main(string[] args) { string s = "You can either send email to my work address name@domain.com or to my personal address name.surname@domain.com, but the old name@sub.domain.net is no longer valid."; Console.WriteLine(s); Console.WriteLine(s.Obfuscate()); } } }