- The first Regular Expression Library on the Web!

Please support RegExLib Sponsors


Regular Expression Details

Title Test Find email address (RFC 2822 mailbox)
This accepts RFC 2822 email addresses in the form:<br> [email protected] OR<br> Blah &lt;[email protected]&gt;<br> <br> RFC 2822 email 'mailbox':<br> mailbox = name-addr | addr-spec<br> name-addr = [display-name] "<" addr-spec ">"<br> addr-spec = local-part "@" domain<br> domain = rfc2821domain | rfc2821domain-literal<br> <br> local-part conforms to RFC 2822.<br> <br> domain is either:<br> An rfc 2821 domain (EXCEPT that the final sub-domain must consist of 2 or more letters only).<br> OR<br> An rfc 2821 address-literal.<br> (Note, no attempt is made to fully validate an IPv6 address-literal.)<br> <br> Notes:<br> This pattern uses (.NET/Perl only?) features named group "(?&lt;name&gt;)" and alternation/IF (?(name)).<br> <br> See <a href="">this thread</a> for more info, including a version that does not use .NET features.<br> <br> RFC 2822 (and 822) do allow embedded comments, whitespace, and newlines within *some* parts of an email address, but this pattern above DOES NOT.<br> <br> RFC 2822 (and 822) allow the domain to be a simple domain with NO ".", but this pattern requires a compound domain at least one "." in the domain name, as per RFC 2821 (4.1.2).<br> <br> RFC 2822 allows/disallows certain whitespace characters in parts of an email address, such as TAB, CR, LF BUT the pattern above does NOT test for these, and assumes that they are not present in the string (on the basis that these characters are hard to enter into an edit box).
[email protected] | Name Surname <[email protected]> | "b. blah"
name [email protected] | name."surname" | [email protected]
Author Rating: The rating for this expression. Mark Cranness
Your Rating
Bad Good

Enter New Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: Galvanized Steel W Beam Highway Guardrail factory
Name: wei xu
Date: 9/27/2018 1:09:40 AM
Our History Established in 1998, Dinggin Hardware(Dalian)Co.,ltd has been specializing in cast iron pipes&fittings, ductile iron pipes&fittings, highway guardrails, wrought iron balusters and gabions for civil engineering, municipal engineering and infrastructure project. Our head office is located in Dalian, with 2 own factories and 12 cooperate factories. 1998: Dinggin Hardware was founded as Dalian Casting Hardware company 2009: Combined with Good Pipes Co.,ltd 2011: Change the name into Dinggin Hardware since the business has been broadened a lot 2017: Invest about $2,000,000 into factory to equip new facilities. Our Factory Top manufacturer for cast iron pipes & fittings of ASTM A888, EN877, production capacity 2500 tons/month for pipes, 500 tons/month for fittings; Best quality of ISO2531,EN545 ductile iron pipes&fittings, production capacity 6000 tons/month for pipes, 2000 tons/month for fittings; The biggest factory of guardrail, production capacity 2600 tons/month; The most advanced producer of gabions, production capacity 1000000 sqm/day. Our Product Cast iron pipes and fittings, ductile iron pipes and fittings, highway guardrails, wrought iron balusters and gabions. Product Application Water supply & drainage pipes networks, Gardening, Road safety products. Our Certificate ISO9001,UPC,CE,WRAS. Production Equipment Automatic casting production lines; Shot blasting machines; CNC for moulds; Automatic coating machine; steel cutting machine; Punching and Rolling lines; Biggest galvanize pool in China. Production Market USA,GERMANY,FINLAND,NORWAY,ENGLAND,TURKEY,HONGKONG,SINGAPORE, PHILIPPINES, AUSTRIA, AUSTRILIA,NEW ZEALAND, IRAQ,PAKISTAN ETC. Our Service Installation guide; Technical service; Strictly inspection before loading; 24hx7 service; 6months quality assurance after arrival.Galvanized Steel W Beam Highway Guardrail factory website:

Title: RFC 2822
Name: anonymous
Date: 4/3/2013 2:42:28 AM
This Regex does not accept some certain RFC 2822 compliant email address, for example: "test\blah" "first".middle."last" I know these are very specific and unusual, but they are correct for RFC 2822. Point in case: You say "This accepts RFC 2822 email addresses in the form". Either you accept RFC 2822 compliant email addresses or you don't. There isn't really something inbetween. I still see the effort taken, so congratulations on this one. For reference:

Title: email validation
Name: sujatha
Date: 10/31/2011 6:25:35 AM
i want to validate emailaddress like [email protected] using regular expression.

Title: Not working
Name: le_mig
Date: 3/24/2011 5:43:16 AM
Not only is this regex crashing my server, it's crashing THIS server when I use it's built-in tester. Please update!

Title: does not working in java
Name: gowtham
Date: 2/4/2011 1:07:42 AM
it is show illegal escape character error

Title: pound symbol in regular expression
Name: vijaya
Date: 11/26/2009 4:35:57 AM
i need to how to recognise pound symbol in regular expression can u plz tel me

Title: About multiple email ids
Name: priyanaka1212
Date: 5/26/2009 8:42:36 AM
Could you please help me ..... I want the regular expression which validate the email ids of format as specied bellow. These are emailids separated by commas .You can say these all email ids are imported from the email address book. Here problem arrises because "firstname last name" are in diffrent diffrent formats and email ids are enclosed in < > . "firstName LastName" <[email protected]>, "firstName,LastName"<[email protected]>, "firstName" <[email protected]>,<[email protected]>, "Amar :)" <[email protected]>, [email protected] ,"[email protected][email protected]@"<[email protected]> ,"firstname. lastname"<[email protected]>

Title: About multiple email ids
Name: priyanaka1212
Date: 5/26/2009 8:41:53 AM
Could you please help me ..... I want the regular expression which validate the email ids of format as specied bellow. These are emailids separated by commas .You can say these all email ids are imported from the email address book. Here problem arrises because "firstname last name" are in diffrent diffrent formats and email ids are enclosed in < > . "firstName LastName" <[email protected]>, "firstName,LastName"<[email protected]>, "firstName" <[email protected]>,<[email protected]>, "Amar :)" <[email protected]>, [email protected] ,"[email protected][email protected]@"<[email protected]> ,"firstname. lastname"<[email protected]>

Title: Wrong
Name: Leonardo de Jesus
Date: 5/8/2009 10:46:49 AM
Test this email: "[email protected]" Error on define the result...

Title: Does not work
Name: Norwegian
Date: 5/7/2009 2:50:16 AM
løkpø[email protected]æ should be valid.

Title: Manager
Name: Nirmal
Date: 9/6/2008 7:12:47 AM
The RegEx is too long.. it can be short even

Title: Python version?
Name: Antisense
Date: 7/22/2008 5:00:47 AM
Has anyone come up with a Python version yet? I'm still struggling with getting this to work.

Title: REGular for this email([email protected])
Name: Muhammad Arfan
Date: 7/2/2008 8:44:48 AM
I need regular expression that validate this email address [email protected] kindly help me.

Title: Java Compliant
Name: Miniml
Date: 6/17/2008 4:19:25 PM
^((?>[a-zA-Z\\d!#$%&'*+\\-/=?^_`{|}~]+\\x20*|\"((?=[\\x01-\\x7f])[^\"\\\\]|\\\\[\\x01-\\x7f])*\"\\x20*)*(?<angle><))?((?!\\.)(?>\\.?[a-zA-Z\\d!#$%&'*+\\-/=?^_`{|}~]+)+|\"((?=[\\x01-\\x7f])[^\"\\\\]|\\\\[\\x01-\\x7f])*\")@(((?!-)[a-zA-Z\\d\\-]+(?<!-)\\.)+[a-zA-Z]{2,}|\\[(((?(?<!\\[)\\.)(25[0-5]|2[0-4]\\d|[01]?\\d?\\d)){4}|[a-zA-Z\\d\\-]*[a-zA-Z\\d]:((?=[\\x01-\\x7f])[^\\\\\\[\\]]|\\\\[\\x01-\\x7f])+)\\])(?(angle)>)$ Enjoy!

Title: PHP escaped
Name: 123
Date: 6/9/2008 2:03:21 PM

Title: use
Name: SMHoff
Date: 4/23/2008 9:06:42 PM
First: Create the regex validator in markup. Next: Set the validationexpression in codebehind: private string regexString = "^((?>[a-zA-Z\\d!#$%&'*+\\-/=?^_`{|}~]+\x20*|\"((?=[\x01-\x7f])[^\"\\]|\\[\x01-\x7f])*\"\x20*)*(?<angle><))?((?!\\.)(?>\\.?[a-zA-Z\\d!#$%&'*+\\-/=?^_`{|}~]+)+|\"((?=[\x01-\x7f])[^\"\\]|\\[\x01-\x7f])*\")@(((?!-)[a-zA-Z\\d\\-]+(?<!-)\\.)+[a-zA-Z]{2,}|\\[(((?(?<!\\[)\\.)(25[0-5]|2[0-4]\\d|[01]?\\d?\\d)){4}|[a-zA-Z\\d\\-]*[a-zA-Z\\d]:((?=[\x01-\x7f])[^\\\\[\\]]|\\[\x01-\x7f])+)\\])(?(angle)>)$"; protected override void OnPreRender(EventArgs e) { this.EmailRegex.ValidationExpression = this.regexString; base.OnPreRender(e); }

Title: <qqq>
Name: yes
Date: 2/14/2008 1:23:54 PM

Title: PHP Friendly variant
Name: FractalizeR
Date: 12/19/2007 1:46:56 PM
$regExp = '\^\(\(\?\>\[a-zA-Z\\d\!#\$%&'\*\+\\-/\=\?\^_`\{\|\}~\]\+\\x20\*\|"\(\(\?\=\[\\x01-\\x7f\]\)\[\^"\\\\\]\|\\\\\[\\x01-\\x7f\]\)\*"\\x20\*\)\*\(\?\<angle\>\<\)\)\?\(\(\?\!\\\.\)\(\?\>\\\.\?\[a-zA-Z\\d\!#\$%&'\*\+\\-/\=\?\^_`\{\|\}~\]\+\)\+\|"\(\(\?\=\[\\x01-\\x7f\]\)\[\^"\\\\\]\|\\\\\[\\x01-\\x7f\]\)\*"\)@\(\(\(\?\!-\)\[a-zA-Z\\d\\-\]\+\(\?\<\!-\)\\\.\)\+\[a-zA-Z\]\{2,\}\|\\\[\(\(\(\?\(\?\<\!\\\[\)\\\.\)\(25\[0-5\]\|2\[0-4\]\\d\|\[01\]\?\\d\?\\d\)\)\{4\}\|\[a-zA-Z\\d\\-\]\*\[a-zA-Z\\d\]\:\(\(\?\=\[\\x01-\\x7f\]\)\[\^\\\\\\\[\\\]\]\|\\\\\[\\x01-\\x7f\]\)\+\)\\\]\)\(\?\(angle\)\>\)\$';

Title: The pattern doesn't work in Java
Name: James Xu
Date: 1/11/2007 9:47:09 AM
The pattern looks great. However, I got compiling exception when I tried to use it in Java code. I know that Java has more restrict syntax checking than Perl. Can any one try it in Java and let me know the correct one? Thanks a lot!

Title: Error in ruby.
Name: Markus
Date: 10/18/2006 2:42:36 PM
I get the following error trying to use this regex in Ruby: undefined (?...) sequence I had to modify the regex pattern to satisfy Ruby syntax requirements. Here's the modified pattern. ^((?>[a-zA-Z\d!#$\%&'*+\-\/=?^_`{|}~]+\x20*|"((?=[\x01-\x7f])[^"\\]|\\[\x01-\x7f])*"\x20*)*(?<angle><))?((?!\.)(?>\.?[a-zA-Z\d!#$\%&'*+\-\/=?^_`{|}~]+)+|"((?=[\x01-\x7f])[^"\\]|\\[\x01-\x7f])*")@(((?!-)[a-zA-Z\d\-]+(?<!-)\.)+[a-zA-Z]{2,}|\[(((?(?<!\[)\.)(25[0-5]|2[0-4]\d|[01]?\d?\d)){4}|[a-zA-Z\d\-]*[a-zA-Z\d]:((?=[\x01-\x7f])[^\\\[\]]|\\[\x01-\x7f])+)\])(?(angle)>)$ Any ideas what might be wrong here?

Title: ABNF to RegEx
Name: Matthew Peck
Date: 10/6/2006 12:57:41 PM
I've been using this RegEx for about a year now. Love it, thanks a ton. It occurs to me that one could, thanks to formal parsing grammars, write an automated converter to take Augmented BNF (as found, for instance, in RFCs) and generate regular expressions to validate it. Any interest in tackling this for us?

Title: Disappointing
Name: See Sharp
Date: 8/25/2006 11:03:16 AM
x20 causing me problems with this exp. Can't use it in the validationexpression attribute of ASP.Net Regular Expression Validator server control

Title: What kind of domain is that?
Name: Thomas Watson Steen
Date: 3/27/2006 2:26:59 PM
Hi again... I just found the answer to my question in one of the previous comments, so never mind that - sorry... I do have another one though: The last part of the regex says: [a-zA-Z\d\-]*[a-zA-Z\d]:((?=[\x01-\x7f])[^\\\[\]]|\\[\x01-\x7f])+ What kind of domain is that??? I can't seem to find it in RFC2822.

Title: Is atomic grouping required?
Name: Thomas Watson Steen
Date: 3/27/2006 8:14:47 AM
Hi I'm trying to convert this regex to be used in JavaScript. The first part uses atomic grouping (see ) - But is this really necessary? I can't imagine that it will validate wrong if it is removed, but will it give performance issues?

Title: vbscript?
Name: santiago
Date: 1/19/2006 1:27:10 PM
Hello. First of all, great work Mark! I have a little question... I'm new to regular expressions, and I'd like to know why this wouldn't work in vbscript 5. Does anybody know what the differences in the sintaxes are? Thanks!

Title: Re: Group addresses
Name: Mark Cranness
Date: 12/31/2005 4:40:04 PM
It does not handle an RFC 2822 'address' or 'group'. It only handles an RFC 2822 'mailbox'. (For the benefit of everybody else, a 'mailbox' is a single email address, a 'group' is a collection of one or more email addresses with a name prefix, and an 'address' is either a 'mailbox' or a 'group'.)

Title: Group addresses
Name: Alex
Date: 12/30/2005 7:53:19 PM
Hi Mark, Congratulations for this expression, which is the best I have found so far to validate against RFC 2822 (822). There are however, I think, some false negatives concerning group addresses: "[email protected],[email protected],[email protected]" Examples in section A.1.3 of RFC 2822. All the best.

Title: error on copy and paste in xml
Name: Kishore
Date: 12/20/2005 2:29:40 AM
HI Mark, This code sounds great..but iam getting this error when i copied into my xml file.Can you please help me. SEVERE: Parse Fatal Error at line 11 column 42: The entity name must immediately follow the '&' in the entity reference. org.xml.sax.SAXParseException: The entity name must immediately follow the '&' in the entity reference.

Title: PHP?
Name: spoon
Date: 11/17/2005 2:56:41 PM
WOuld anyone be willing to make this PHP friendly? I have been trying for a while now and I am having no luck. I've tried to escape so many different parts of this regex to get it to work, but I just cant.

Title: Valid address not matching
Name: Andy Calderbank
Date: 9/11/2005 10:34:16 PM
I think this is relavant and not a distinct. Doesn't match Email address [email protected]#1162167621 At a quick scan of RFC 2822 I can't find any notes about decimal IPs, though in 821 there is this passage: Sometimes a host is not known to the translation function and communication is blocked. To bypass this barrier two numeric forms are also allowed for host "names". One form is a decimal integer prefixed by a pound sign, "#", which indicates the number is the address of the host. Another form is four small decimal integers separated by dots and enclosed by brackets, e.g., "[]", which indicates a 32-bit ARPA Internet Address in four 8-bit fields.

Title: Escaped Email Address?
Name: James White
Date: 8/13/2005 8:53:42 AM
Hi, I was wondering if anyone could help translating this to a form that would capture escaped (in XML or HTML) email addresses where the pattern would match Friendly Name &lt;[email protected]&gt; or just &lt;[email protected]&gt; I've struggled with it for a bit but have definitely hit the limit of my regular expressions knowledge. Thanks! James regex(.)

Title: Re: didn't work
Name: Mark Cranness
Date: 3/11/2005 5:34:25 PM
Try this instead: if($email =~ m/^((?>[a-zA-Z\d!#$%&'*+\-\/=?^_`{|}~]+\x20*|"((?=[\x01-\x7f])[^"\\]|\\[\x01-\x7f])*"\x2 0*)*(?<angle><))?((?!\.)(?>\.?[a-zA-Z\d!#$%&'*+\-\/=?^_`{|}~]+)+|"((?=[\x01-\x7f])[^"\\]|\\[\x01-\x7f ])*")@(((?!-)[a-zA-Z\d\-]+(?<!-)\.)+[a-zA-Z]{2,}|\[(((?(?<!\[)\.)(25[0-5]|2[0-4]\d|[01]?\d?\d)){4}|[ a-zA-Z\d\-]*[a-zA-Z\d]:((?=[\x01-\x7f])[^\\\[\]]|\\[\x01-\x7f])+)\])(?(angle)>)$/i) { print "matched"; } You have to "escape" the / character and use "\/" instead.

Title: didn't work
Name: Kalen
Date: 3/9/2005 12:45:54 PM
this code snippet produced an error. I copied and pasted directly from this site and haven't looked into the regex at all...just thought I'd post. Unmatched ( in regex; marked by <-- HERE in m/^_`{|}~]+\x20*|"(( <-- HERE / at r line 3. my $email = "Name Surname <[email protected]>"; if($email =~ m/^((?>[a-zA-Z\d!#$%&'*+\-/=?^_`{|}~]+\x20*|"((?=[\x01-\x7f])[^"\\]|\\[\x01-\x7f])*"\x20*)*(?<angle><))?((?!\.)(?>\.?[a-zA-Z\d!#$%&'*+\-/=?^_`{|}~]+)+|"((?=[\x01-\x7f])[^"\\]|\\[\x01-\x7f])*")@(((?!-)[a-zA-Z\d\-]+(?<!-)\.)+[a-zA-Z]{2,}|\[(((?(?<!\[)\.)(25[0-5]|2[0-4]\d|[01]?\d?\d)){4}|[a-zA-Z\d\-]*[a-zA-Z\d]:((?=[\x01-\x7f])[^\\\[\]]|\\[\x01-\x7f])+)\])(?(angle)>)$/i) { print "matched"; } print "reading $email\n";

Title: Invalid when used on Client Side Regex engines
Name: John
Date: 1/27/2005 12:46:41 PM
Sorry to post again, but this expression is invalid on client side regex engines, which is the reason for it not working with the ASP.NET RegularExpressionValidator. If there's a way around this, I'd love to hear it. Thanks, John

Title: ASP.NET RegularExpressionValidator
Name: John
Date: 1/27/2005 12:40:16 PM
Well, I'm having the same problem as Josh (the prior post) and I've tried just about everything to get it to work with this control. What I believe the problem to be is that because this is an ASP.NET control, it's converting '&' to '&amp;' and '"' to '&quot;' To try and side step this, I set the .ValidationExpression property of the control to the string posted by Mark in the codebehind, but that also didn't make the expression work. All of this leads me to believe that the RegularExpressionValidator contol does not use the .NET Regex engine in its entirety, this expression is too long for the control to handle, or I'm overlooking something. I think the latter is the most likely, but for now, all I can suggest is use a different regular expression.

Title: How to incorporate into a ASP.NET RegularExpressionValidator ValidationExpression
Name: Josh
Date: 1/26/2005 7:17:55 PM
This looks like a comprehensive expression. Does anyone know how to incorporate it in a ASP.NET RegularExpressionValidator ValidationExpression statement? I can not contain the expression using single or double quotes because both are in the expression. Thanks.

Title: Thanks for reading 2822
Name: John Sinclair
Date: 1/26/2005 2:55:27 PM
A million thanks to you... someone who actually read the RFC2822 spec that supplanted 822 years ago. The current specs specifically state US ASCII characters from 33 through 90 and 94 through 126 are allowed in the local part of the address. So we could possibly encounter Bob's_Pies or Edna~Mae~Feltcher.

Title: Re: Convert to c#
Name: Mark Cranness
Date: 12/23/2004 4:16:31 PM
Like Axel says, it helps to use @"..." for strings, and you also need to DOUBLE every " (quote) character. I use this: private const string RegularExpression_Email = @"^((?>[a-zA-Z\d!#$%&'*+\-/=?^_`{|}~]+\x20*" + @"|""((?=[\x01-\x7f])[^""\\]|\\[\x01-\x7f])*""\x20*)*" + @"(?<angle><))?" + @"((?!\.)(?>\.?[a-zA-Z\d!#$%&'*+\-/=?^_`{|}~]+)+" + @"|""((?=[\x01-\x7f])[^""\\]|\\[\x01-\x7f])*"")" + @"@" + @"(((?!-)[a-zA-Z\d\-]+(?<!-)\.)+[a-zA-Z]{2,}" + @"|\[" + @"(((?(?<!\[)\.)(25[0-5]|2[0-4]\d|[01]?\d?\d)){4}" + @"|[a-zA-Z\d\-]*[a-zA-Z\d]:" + @"((?=[\x01-\x7f])[^\\\[\]]|\\[\x01-\x7f])+)" + @"\])" + @"(?(angle)>)$";

Title: Re: Convert to c#
Name: Axel
Date: 12/22/2004 12:13:20 PM
try string regex = @"..."; where ... is the expression.

Title: Convert to c#
Name: Mike
Date: 12/19/2004 8:48:49 PM
I've tried to use this regular expression in C# however, i cannot get it to compile due to syntax errors. does anyone know how this expression needs to be converted so that it will compile in c#?

Title: Re: Question
Name: Mark Cranness
Date: 11/19/2004 9:35:26 PM
> then Match[1] is FirstName LastName< I didn't particularly plan for allowing easily capturing the parts of the email address, but it could be changed to allow that. For example, if you replace the first bit with: ^((?<displayname>(?>[a-zA-Z\d!#$%&'*+\-/=?^_`{|}~]+\x20*|"((?=[\x01-\x7f])[^"\\]|\\[\x01-\x7f])*"\x20*)*)(?<angle><))$ Match match = Regex.Match(email, emailRegex); match.Groups["displayname"].Value should pick out the display-name part. Same could be done for local-part, domain etc.

Title: Question
Name: Axel
Date: 11/19/2004 7:21:56 AM
First, thank you for all your efforts! Now the question: if I use an address in the form FirstName LastName<[email protected]> then Match[1] is FirstName LastName< i.e. with the angle bracket at the end. I'm a bit new to regular expressions and I wonder if this is the intended result or if the bracket should not be there? Thanks, Axel

Title: Get a girlfriend
Name: Alex
Date: 11/9/2004 10:44:30 AM
This is a great thread, you've obviously spent a lot of time and effort on this expressions and I am indeed impressed. But, don't you think you need to get out more, get a girlfriend maybe?!

Title: Re: angle?
Name: Mark Cranness
Date: 10/9/2004 10:57:25 PM
> angle?...The Regex Coach, it says: > Character 'a' may not follow '(?<' at position 92 Are you using Python? (or Perl?) Try this instead: (?P<angle><) The syntax I have works for .NET, it looks like it might be .NET specific. It is the syntax for a "Named Capture". > ...the built-in test feature on this > site does not validate [email protected] See my post "Re: Incorrect behaviour?" 9/24/2004 6:52:03 PM above; Open up the "Options" bar, and make sure that "Ignore Pattern Whitespace" is selected (I remove whitespace when I use it in my code).

Title: angle?
Name: Brian
Date: 10/6/2004 1:43:32 PM
When I enter this regex into The Regex Coach, it says: Character 'a' may not follow '(?<' at position 92 Also, doing the built-in test feature on this site does not validate [email protected]

Title: Re: Timeout/hang problems and , (comma) in local-part and . (period) at end of local-part
Name: Mark Cranness
Date: 10/4/2004 8:26:24 PM
Fixed two problems: + A similar time-out problem existed with the local-part of the email address (in front of the "@"). Some of the sub-expressions are of the form: ^(a+|b.*)+$ ... and if you enter aaaaaaaaaaaaaaaaaaC this will do a lot of backtracking before failing. Changing this to: ^(?>a+|b.*)+$ ... prevents backtracking (which is appropriate anyway, as an RFC 2822 email address is supposed to be parseable without backtracking). + The display-name and local-part had a character class that included "+-/". This should have been (and now is) "+\-/". It was allowing commas (",") in the local-part, and it was allowing a period (".") at the end of the local-part (just before the "@").

Title: Re: Timeout/hang problems
Name: Mark Cranness
Date: 10/1/2004 9:36:41 PM
Now fixed. (I added "?>" to the display-name part of the expression, to make that part non-backtracking; "subexpression is fully matched once, and then does not participate piecemeal in backtracking") PS: In the testing I did (in response to your post), the excessive time depended on the word length... ie, adding a letter to a word increased the loop time, but adding a space to break words up, decreased the time.

Title: Timeout/hang problems
Name: Ian Cummings
Date: 9/28/2004 9:48:35 AM
I've found a problem with the regex when its trying to parse an email that is actually invalid. On the website test page I get a timeout error. When I run the regex in my own console test app, it just takes ages to return from Regex.IsMatch The problem only seems to happen for the name-addr format, ie the ones with the angle brackets, and only if the ending angle bracket is missing. The time taken seems to be related to the length of the "display name" portion of the address, and this value seems to be exponential at first glance. Try these addresses in the test page: Mr Foo Wibble Barf Here<[email protected] Mr Foo Wibble Barf There<[email protected] I found the first one would be just about OK. The second one would timeout. In my own test app, i entered an even longer display name and it took over 7 minutes to return.

Title: Re: Incorrect behaviour?
Name: Mark Cranness
Date: 9/24/2004 6:52:03 PM
When testing this expression, make sure you click and enable the "Ignore Pattern Whitespace" checkbox. I have put line-breaks (newlines) into the pattern to make it more readable, but you need to remove these when the pattern is used in your code.

Title: Incorrect behaviour?
Name: Freek Versteijn
Date: 9/23/2004 11:45:01 AM
My own email address [email protected] does not validate

Title: Re: Fails to recognize as invalid an addr with DBCS chars
Name: Mark Cranness
Date: 7/10/2004 8:06:34 AM
Fixed now. DBCS characters anywhere will be treated as invalid.

Title: Fails to recognize as invalid an addr with DBCS chars
Name: Rob Steel
Date: 7/8/2004 1:26:30 PM
the following address should be invalid, but this regex doesn't catch it.. tÉ[email protected] [email protected]

Title: Re: Modification
Name: Mark Cranness
Date: 5/18/2004 8:11:48 PM
> how can this regex be modified to pull apart an email > address into its parts? If you are using .NET, read this: You wrap the part you want captured in (?<name>...) "name" is a name you choose, the "<>" characters are required, "..." is the expression you want to capture.

Title: Modification
Name: Kevin
Date: 5/18/2004 5:49:34 PM
how can this regex be modified to pull apart an email address into its parts?

Title: Re: more addresses
Name: Mark Cranness
Date: 5/16/2004 5:06:58 AM
You're a hard task-master Mike! ;-) > The regex matches > '@[] > [email protected][999.999.999.300] Not anymore. (It does still match ' > but disallows > [email protected] It still disallows this. I can't see that is a valid domain name according to RFC 1035. It will allow: [email protected][], and I believe it was intended that a domain literal is used for IP addresses.

Title: more addresses
Name: Mike
Date: 5/15/2004 10:52:05 AM
The regex matches '@[] [email protected][999.999.999.300] but disallows [email protected]

Title: Domain now conforms to RFC 1034
Name: Mark Cranness
Date: 5/15/2004 3:24:35 AM
I've changed the domain pattern (but not the domain literal pattern) so that domains must conform to RFC 1034. This now disallows [email protected] [email protected]!#$%&' (RFC 2822 still allows punctuation in the local-part in front of the "@" sign ...)

Title: "Valid e-mail address" is a tricky matter
Name: Mike
Date: 5/15/2004 1:26:58 AM
Mark, Actually, it depends on the definition of the term "valid e-mail address". Most people (me too!) think that it means "E-mail clients, for example, MS Outlook or Outlook Express are able at least to send an e-mail to the address".

Title: Re: Problems
Name: Mark Cranness
Date: 5/14/2004 6:54:27 PM
> Unfortunately, the regex allows followed addresses ... Yes it does allow those addresses. Those are syntactically valid email addresses, according to RFC 2822 (!!) A more useful regexp (than the one I've written) might enforce more restrictions to disallow the examples you give, but then it would disallow some valid RFC 2822 addresses. (At the time, I was following RFC 2822 slavishly, perhaps too slavishly.), sections 3.2.4 & 3.4.1, the local-part and domain can contain some punctuation characters !#$%&'*+-/=?^_`{|}~ Section 3.4.1 & 3.2.3(FWSP) & 2.2.2(WSP): domain-literal can contain space characters and quoted literals "\a"

Title: Problems
Name: Mike
Date: 5/14/2004 5:24:54 PM
Unfortunately, the regex allows followed addresses !#&<'.%&'@abc.0123> <'@[\a\a\7 ]> [email protected]!#$%&' It also allows "<>", but you can't send it by, for example, MS Outlook. Use Regex Master to validate regular expressions, potential problem location, match predicting, etc

Copyright © 2001-2020, | ASP.NET Tutorials