Skip to content

Instantly share code, notes, and snippets.

@MetroWind
Created June 10, 2022 22:03
Show Gist options
  • Save MetroWind/73d165f6112ea773ceecc9a146f9597e to your computer and use it in GitHub Desktop.
Save MetroWind/73d165f6112ea773ceecc9a146f9597e to your computer and use it in GitHub Desktop.
Email validation test
first.last@iana.org
Valid
1234567890123456789012345678901234567890123456789012345678901234@iana.org
Valid
first.last@sub.do,com
Invalid
"first\"last"@iana.org
Valid
first\@last@iana.org
Invalid
"first@last"@iana.org
Valid
"first\\last"@iana.org
Valid
x@x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x2
Valid
1234567890123456789012345678901234567890123456789012345678@12345678901234567890123456789012345678901234567890123456789.12345678901234567890123456789012345678901234567890123456789.123456789012345678901234567890123456789012345678901234567890123.iana.org
Valid
first.last@[12.34.56.78]
Valid
first.last@[IPv6:::12.34.56.78]
Valid
first.last@[IPv6:1111:2222:3333::4444:12.34.56.78]
Valid
first.last@[IPv6:1111:2222:3333:4444:5555:6666:12.34.56.78]
Valid
first.last@[IPv6:::1111:2222:3333:4444:5555:6666]
Valid
first.last@[IPv6:1111:2222:3333::4444:5555:6666]
Valid
first.last@[IPv6:1111:2222:3333:4444:5555:6666::]
Valid
first.last@[IPv6:1111:2222:3333:4444:5555:6666:7777:8888]
Valid
first.last@x23456789012345678901234567890123456789012345678901234567890123.iana.org
Valid
first.last@3com.com
Valid
first.last@123.iana.org
Valid
123456789012345678901234567890123456789012345678901234567890@12345678901234567890123456789012345678901234567890123456789.12345678901234567890123456789012345678901234567890123456789.12345678901234567890123456789012345678901234567890123456789.12345.iana.org
Invalid
first.last
Invalid
12345678901234567890123456789012345678901234567890123456789012345@iana.org
Invalid
.first.last@iana.org
Invalid
first.last.@iana.org
Invalid
first..last@iana.org
Invalid
"first"last"@iana.org
Invalid
"first\last"@iana.org
Valid
"""@iana.org
Invalid
"\"@iana.org
Invalid
""@iana.org
Invalid
first\\@last@iana.org
Invalid
first.last@
Invalid
x@x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456
Invalid
first.last@[.12.34.56.78]
Invalid
first.last@[12.34.56.789]
Invalid
first.last@[::12.34.56.78]
Invalid
first.last@[IPv5:::12.34.56.78]
Invalid
first.last@[IPv6:1111:2222:3333::4444:5555:12.34.56.78]
Valid
first.last@[IPv6:1111:2222:3333:4444:5555:12.34.56.78]
Invalid
first.last@[IPv6:1111:2222:3333:4444:5555:6666:7777:12.34.56.78]
Invalid
first.last@[IPv6:1111:2222:3333:4444:5555:6666:7777]
Invalid
first.last@[IPv6:1111:2222:3333:4444:5555:6666:7777:8888:9999]
Invalid
first.last@[IPv6:1111:2222::3333::4444:5555:6666]
Invalid
first.last@[IPv6:1111:2222:3333::4444:5555:6666:7777]
Valid
first.last@[IPv6:1111:2222:333x::4444:5555]
Invalid
first.last@[IPv6:1111:2222:33333::4444:5555]
Invalid
first.last@example.123
Valid
first.last@com
Valid
first.last@-xample.com
Invalid
first.last@exampl-.com
Invalid
first.last@x234567890123456789012345678901234567890123456789012345678901234.iana.org
Invalid
"Abc\@def"@iana.org
Valid
"Fred\ Bloggs"@iana.org
Valid
"Joe.\\Blow"@iana.org
Valid
"Abc@def"@iana.org
Valid
"Fred Bloggs"@iana.org
Valid
user+mailbox@iana.org
Valid
customer/department=shipping@iana.org
Valid
$A12345@iana.org
Valid
!def!xyz%abc@iana.org
Valid
_somename@iana.org
Valid
dclo@us.ibm.com
Valid
abc\@def@iana.org
Invalid
abc\\@iana.org
Invalid
peter.piper@iana.org
Valid
Doug\ \"Ace\"\ Lovell@iana.org
Invalid
"Doug \"Ace\" L."@iana.org
Valid
abc@def@iana.org
Invalid
abc\\@def@iana.org
Invalid
abc\@iana.org
Invalid
@iana.org
Invalid
doug@
Invalid
"qu@iana.org
Invalid
ote"@iana.org
Invalid
.dot@iana.org
Invalid
dot.@iana.org
Invalid
two..dot@iana.org
Invalid
"Doug "Ace" L."@iana.org
Invalid
Doug\ \"Ace\"\ L\.@iana.org
Invalid
hello world@iana.org
Invalid
gatsby@f.sc.ot.t.f.i.tzg.era.l.d.
Invalid
test@iana.org
Valid
TEST@iana.org
Valid
1234567890@iana.org
Valid
test+test@iana.org
Valid
test-test@iana.org
Valid
t*est@iana.org
Valid
+1~1+@iana.org
Valid
{_test_}@iana.org
Valid
"[[ test ]]"@iana.org
Valid
test.test@iana.org
Valid
"test.test"@iana.org
Valid
test."test"@iana.org
Valid
"test@test"@iana.org
Valid
test@123.123.123.x123
Valid
test@123.123.123.123
Valid
test@[123.123.123.123]
Valid
test@example.iana.org
Valid
test@example.example.iana.org
Valid
test.iana.org
Invalid
test.@iana.org
Invalid
test..test@iana.org
Invalid
.test@iana.org
Invalid
test@test@iana.org
Invalid
test@@iana.org
Invalid
-- test --@iana.org
Invalid
[test]@iana.org
Invalid
"test\test"@iana.org
Valid
"test"test"@iana.org
Invalid
()[]\;:,><@iana.org
Invalid
test@.
Invalid
test@example.
Invalid
test@.org
Invalid
test@123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012.com
Invalid
test@example
Valid
test@[123.123.123.123
Invalid
test@123.123.123.123]
Invalid
NotAnEmail
Invalid
@NotAnEmail
Invalid
"test\\blah"@iana.org
Valid
"test\blah"@iana.org
Valid
"test\&#13;blah"@iana.org
Valid
"test&#13;blah"@iana.org
Invalid
"test\"blah"@iana.org
Valid
"test"blah"@iana.org
Invalid
customer/department@iana.org
Valid
_Yosemite.Sam@iana.org
Valid
~@iana.org
Valid
.wooly@iana.org
Invalid
wo..oly@iana.org
Invalid
pootietang.@iana.org
Invalid
.@iana.org
Invalid
"Austin@Powers"@iana.org
Valid
Ima.Fool@iana.org
Valid
"Ima.Fool"@iana.org
Valid
"Ima Fool"@iana.org
Valid
Ima Fool@iana.org
Invalid
phil.h\@\@ck@haacked.com
Invalid
"first"."last"@iana.org
Valid
"first".middle."last"@iana.org
Valid
"first\\"last"@iana.org
Invalid
"first".last@iana.org
Valid
first."last"@iana.org
Valid
"first"."middle"."last"@iana.org
Valid
"first.middle"."last"@iana.org
Valid
"first.middle.last"@iana.org
Valid
"first..last"@iana.org
Valid
foo@[\1.2.3.4]
Invalid
"first\\\"last"@iana.org
Valid
first."mid\dle"."last"@iana.org
Valid
Test.&#13;&#10; Folding.&#13;&#10; Whitespace@iana.org
Valid
first."".last@iana.org
Invalid
first\last@iana.org
Invalid
Abc\@def@iana.org
Invalid
Fred\ Bloggs@iana.org
Invalid
Joe.\\Blow@iana.org
Invalid
first.last@[IPv6:1111:2222:3333:4444:5555:6666:12.34.567.89]
Invalid
"test\&#13;&#10; blah"@iana.org
Invalid
"test&#13;&#10; blah"@iana.org
Valid
{^c\@**Dog^}@cartoon.com
Invalid
(foo)cal(bar)@(baz)iamcal.com(quux)
Valid
cal@iamcal(woo).(yay)com
Valid
"foo"(yay)@(hoopla)[1.2.3.4]
Invalid
cal(woo(yay)hoopla)@iamcal.com
Valid
cal(foo\@bar)@iamcal.com
Valid
cal(foo\)bar)@iamcal.com
Valid
cal(foo(bar)@iamcal.com
Invalid
cal(foo)bar)@iamcal.com
Invalid
cal(foo\)@iamcal.com
Invalid
first().last@iana.org
Valid
first.(&#13;&#10; middle&#13;&#10; )last@iana.org
Valid
first(12345678901234567890123456789012345678901234567890)last@(1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890)iana.org
Invalid
first(Welcome to&#13;&#10; the ("wonderful" (!)) world&#13;&#10; of email)@iana.org
Valid
pete(his account)@silly.test(his host)
Valid
c@(Chris's host.)public.example
Valid
jdoe@machine(comment). example
Valid
1234 @ local(blah) .machine .example
Valid
first(middle)last@iana.org
Invalid
first(abc.def).last@iana.org
Valid
first(a"bc.def).last@iana.org
Valid
first.(")middle.last(")@iana.org
Valid
first(abc("def".ghi).mno)middle(abc("def".ghi).mno).last@(abc("def".ghi).mno)example(abc("def".ghi).mno).(abc("def".ghi).mno)com(abc("def".ghi).mno)
Invalid
first(abc\(def)@iana.org
Valid
first.last@x(1234567890123456789012345678901234567890123456789012345678901234567890).com
Valid
a(a(b(c)d(e(f))g)h(i)j)@iana.org
Valid
a(a(b(c)d(e(f))g)(h(i)j)@iana.org
Invalid
name.lastname@domain.com
Valid
.@
Invalid
a@b
Valid
@bar.com
Invalid
@@bar.com
Invalid
a@bar.com
Valid
aaa.com
Invalid
aaa@.com
Invalid
aaa@.123
Invalid
aaa@[123.123.123.123]
Valid
aaa@[123.123.123.123]a
Invalid
aaa@[123.123.123.333]
Invalid
a@bar.com.
Invalid
a@bar
Valid
a-b@bar.com
Valid
+@b.c
Valid
+@b.com
Valid
a@-b.com
Invalid
a@b-.com
Invalid
-@..com
Invalid
-@a..com
Invalid
a@b.co-foo.uk
Valid
"hello my name is"@stutter.com
Valid
"Test \"Fail\" Ing"@iana.org
Valid
valid@about.museum
Valid
invalid@about.museum-
Invalid
shaitan@my-domain.thisisminekthx
Valid
test@...........com
Invalid
foobar@192.168.0.1
Valid
"Joe\\Blow"@iana.org
Valid
Invalid \&#10; Folding \&#10; Whitespace@iana.org
Invalid
HM2Kinsists@(that comments are allowed)this.is.ok
Valid
user%uucp!path@berkeley.edu
Valid
"first(last)"@iana.org
Valid
&#13;&#10; (&#13;&#10; x &#13;&#10; ) &#13;&#10; first&#13;&#10; ( &#13;&#10; x&#13;&#10; ) &#13;&#10; .&#13;&#10; ( &#13;&#10; x) &#13;&#10; last &#13;&#10; ( x &#13;&#10; ) &#13;&#10; @iana.org
Valid
first.last @iana.org
Valid
test. &#13;&#10; &#13;&#10; obs@syntax.com
Valid
test.&#13;&#10;&#13;&#10; obs@syntax.com
Invalid
"Unicode NULL \␀"@char.com
Valid
"Unicode NULL ␀"@char.com
Invalid
Unicode NULL \␀@char.com
Invalid
cdburgess+!#$%&'*-/=?+_{}|~test@gmail.com
Valid
first.last@[IPv6:::a2:a3:a4:b1:b2:b3:b4]
Valid
first.last@[IPv6:a1:a2:a3:a4:b1:b2:b3::]
Valid
first.last@[IPv6::]
Invalid
first.last@[IPv6:::]
Valid
first.last@[IPv6::::]
Invalid
first.last@[IPv6::b4]
Invalid
first.last@[IPv6:::b4]
Valid
first.last@[IPv6::::b4]
Invalid
first.last@[IPv6::b3:b4]
Invalid
first.last@[IPv6:::b3:b4]
Valid
first.last@[IPv6::::b3:b4]
Invalid
first.last@[IPv6:a1::b4]
Valid
first.last@[IPv6:a1:::b4]
Invalid
first.last@[IPv6:a1:]
Invalid
first.last@[IPv6:a1::]
Valid
first.last@[IPv6:a1:::]
Invalid
first.last@[IPv6:a1:a2:]
Invalid
first.last@[IPv6:a1:a2::]
Valid
first.last@[IPv6:a1:a2:::]
Invalid
first.last@[IPv6:0123:4567:89ab:cdef::]
Valid
first.last@[IPv6:0123:4567:89ab:CDEF::]
Valid
first.last@[IPv6:::a3:a4:b1:ffff:11.22.33.44]
Valid
first.last@[IPv6:::a2:a3:a4:b1:ffff:11.22.33.44]
Valid
first.last@[IPv6:a1:a2:a3:a4::11.22.33.44]
Valid
first.last@[IPv6:a1:a2:a3:a4:b1::11.22.33.44]
Valid
first.last@[IPv6::11.22.33.44]
Invalid
first.last@[IPv6::::11.22.33.44]
Invalid
first.last@[IPv6:a1:11.22.33.44]
Invalid
first.last@[IPv6:a1::11.22.33.44]
Valid
first.last@[IPv6:a1:::11.22.33.44]
Invalid
first.last@[IPv6:a1:a2::11.22.33.44]
Valid
first.last@[IPv6:a1:a2:::11.22.33.44]
Invalid
first.last@[IPv6:0123:4567:89ab:cdef::11.22.33.44]
Valid
first.last@[IPv6:0123:4567:89ab:cdef::11.22.33.xx]
Invalid
first.last@[IPv6:0123:4567:89ab:CDEF::11.22.33.44]
Valid
first.last@[IPv6:0123:4567:89ab:CDEFF::11.22.33.44]
Invalid
first.last@[IPv6:a1::a4:b1::b4:11.22.33.44]
Invalid
first.last@[IPv6:a1::11.22.33]
Invalid
first.last@[IPv6:a1::11.22.33.44.55]
Invalid
first.last@[IPv6:a1::b211.22.33.44]
Invalid
first.last@[IPv6:a1::b2:11.22.33.44]
Valid
first.last@[IPv6:a1::b2::11.22.33.44]
Invalid
first.last@[IPv6:a1::b3:]
Invalid
first.last@[IPv6::a2::b4]
Invalid
first.last@[IPv6:a1:a2:a3:a4:b1:b2:b3:]
Invalid
first.last@[IPv6::a2:a3:a4:b1:b2:b3:b4]
Invalid
first.last@[IPv6:a1:a2:a3:a4::b1:b2:b3:b4]
Invalid
test@test.com
Valid
test@example.com&#10;
Invalid
test@xn--example.com
Valid
test@Bücher.ch
Valid
#!/usr/bin/env python
import sys, os
import re
pattern = r'(?:(?:\r\n)?[ \t])*(?:(?:(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*|(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)*\<(?:(?:\r\n)?[ \t])*(?:@(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*(?:,@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*)*:(?:(?:\r\n)?[ \t])*)?(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*\>(?:(?:\r\n)?[ \t])*)|(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)*:(?:(?:\r\n)?[ \t])*(?:(?:(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*|(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)*\<(?:(?:\r\n)?[ \t])*(?:@(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*(?:,@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*)*:(?:(?:\r\n)?[ \t])*)?(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*\>(?:(?:\r\n)?[ \t])*)(?:,\s*(?:(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*|(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)*\<(?:(?:\r\n)?[ \t])*(?:@(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*(?:,@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*)*:(?:(?:\r\n)?[ \t])*)?(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*\>(?:(?:\r\n)?[ \t])*))*)?;\s*)'
def validate(email):
return re.fullmatch(pattern, email) is not None
def test():
with open("tests.txt", 'r') as f:
LineNum = 0
Email = None
All = 0
Passed = 0
Failed = 0
FailedCases = []
for Line in f:
if LineNum % 2 == 0:
Email = Line.strip()
else:
Valid = Line.strip() == "Valid"
if Valid == validate(Email):
Passed += 1
else:
Failed += 1
FailedCases.append(Email)
All += 1
LineNum += 1
print("All: {}, passed: {}, failed: {}".format(All, Passed, Failed))
print("\nFailed cases:\n")
for Case in FailedCases:
print(Case)
if __name__ == "__main__":
test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment