The problem with your regular expression in .NET is that the possessive quantifiers aren't supported. If you remove those, it works. Here's the regular expression as a C# string:
@"^[-_a-z0-9\'+*$^&%=~!?{}]+(?:\.[-_a-z0-9\'+*$^&%=~!?{}]+)*@(?:(?![-.])[-a-z0-9.]+(?<![-.])\.[a-z]{2,6}|\d{1,3}(?:\.\d{1,3}){3})(?::\d+)?$"
Here's a test bed for it based on the page you linked to, including all the strings that should match and the first three of those that shouldn't:
using System;
using System.Text.RegularExpressions;
public class Program
{
static void Main(string[] args)
{
foreach (string email in new string[]{
"[email protected]",
"[email protected]",
"hasApostrophe.o'[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]:25",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"&*=?^+{}'[email protected]",
"[email protected]",
"@missingLocal.org",
"missingatSign.net"
})
{
string s = @"^[-_a-z0-9\'+*$^&%=~!?{}]+(?:\.[-_a-z0-9\'+*$^&%=~!?{}]+)*@(?:(?![-.])[-a-z0-9.]+(?<![-.])\.[a-z]{2,6}|\d{1,3}(?:\.\d{1,3}){3})(?::\d+)?$";
bool isMatch = Regex.IsMatch(email, s, RegexOptions.IgnoreCase);
Console.WriteLine(isMatch);
}
}
}
Output:
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
False
False
False
A problem though is that it fails to match some valid email-addresses, such as foo\@[email protected]
. It's better too match too much than too little.