using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"^(?P<Username>[-\w\.]+)(?:\s+\W*at\W*\s+|\s*[^\@\s]*?@[^\@\s]*?\s*)(?P<Domain>([\w\-]+)(?:(?:\.|\s+\W*?dot\W*?\s+)([\w\-]+))+?(?:(?:\.|\s+\W*?dot\W*?\s+)([\w\-]+))??$)";
string substitution = @"\1@\3.\4";
string input = @"Parse email, also distorted ones, and convert them back to the real ones.
Inspirated by dislick's work: https://regex101.com/r/wB7xJ7/1
frenci98@gmail.com
st11389@copernico.bo.it
gigilafontana .at. gmail [dot] com
d98.copernico@gmail.com
domenico-tosello at dotcom-sas dot com
my.e-M4il [at] w3-spAce.org
email@sub-sub.sub dot domain dot info
email@foo dot foo dot foo dot foo";
RegexOptions options = RegexOptions.Multiline;
Regex regex = new Regex(pattern, options);
string result = regex.Replace(input, substitution);
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx