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
[email protected]
Valid
1234567890123456789012345678901234567890123456789012345678901234@iana.org
Valid
[email protected],com
Invalid
"first\"last"@iana.org
Valid
first\@[email protected]
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
[email protected]
Valid
[email protected]
Valid
123456789012345678901234567890123456789012345678901234567890@12345678901234567890123456789012345678901234567890123456789.12345678901234567890123456789012345678901234567890123456789.12345678901234567890123456789012345678901234567890123456789.12345.iana.org
Invalid
first.last
Invalid
12345678901234567890123456789012345678901234567890123456789012345@iana.org
Invalid
[email protected]
Invalid
[email protected]
Invalid
[email protected]
Invalid
"first"last"@iana.org
Invalid
"first\last"@iana.org
Valid
"""@iana.org
Invalid
"\"@iana.org
Invalid
""@iana.org
Invalid
first\\@[email protected]
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
[email protected]
Valid
first.last@com
Valid
[email protected]
Invalid
[email protected]
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
[email protected]
Valid
customer/[email protected]
Valid
[email protected]
Valid
!def!xyz%[email protected]
Valid
[email protected]
Valid
[email protected]
Valid
abc\@[email protected]
Invalid
abc\\@iana.org
Invalid
[email protected]
Valid
Doug\ \"Ace\"\ [email protected]
Invalid
"Doug \"Ace\" L."@iana.org
Valid
abc@[email protected]
Invalid
abc\\@[email protected]
Invalid
abc\@iana.org
Invalid
@iana.org
Invalid
doug@
Invalid
"[email protected]
Invalid
ote"@iana.org
Invalid
[email protected]
Invalid
[email protected]
Invalid
[email protected]
Invalid
"Doug "Ace" L."@iana.org
Invalid
Doug\ \"Ace\"\ L\[email protected]
Invalid
hello [email protected]
Invalid
[email protected].
Invalid
[email protected]
Valid
[email protected]
Valid
[email protected]
Valid
[email protected]
Valid
[email protected]
Valid
t*[email protected]
Valid
[email protected]
Valid
{_test_}@iana.org
Valid
"[[ test ]]"@iana.org
Valid
[email protected]
Valid
"test.test"@iana.org
Valid
test."test"@iana.org
Valid
"test@test"@iana.org
Valid
[email protected]
Valid
[email protected]
Valid
test@[123.123.123.123]
Valid
[email protected]
Valid
[email protected]
Valid
test.iana.org
Invalid
[email protected]
Invalid
[email protected]
Invalid
[email protected]
Invalid
test@[email protected]
Invalid
test@@iana.org
Invalid
-- test [email protected]
Invalid
[test]@iana.org
Invalid
"test\test"@iana.org
Valid
"test"test"@iana.org
Invalid
()[]\;:,><@iana.org
Invalid
test@.
Invalid
test@example.
Invalid
[email protected]
Invalid
test@123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012.com
Invalid
test@example
Valid
test@[123.123.123.123
Invalid
[email protected]]
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/[email protected]
Valid
[email protected]
Valid
[email protected]
Valid
[email protected]
Invalid
[email protected]
Invalid
[email protected]
Invalid
[email protected]
Invalid
"Austin@Powers"@iana.org
Valid
[email protected]
Valid
"Ima.Fool"@iana.org
Valid
"Ima Fool"@iana.org
Valid
Ima [email protected]
Invalid
phil.h\@\@[email protected]
Invalid
"first"."last"@iana.org
Valid
"first".middle."last"@iana.org
Valid
"first\\"last"@iana.org
Invalid
"first"[email protected]
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; [email protected]
Valid
first.""[email protected]
Invalid
first\[email protected]
Invalid
Abc\@[email protected]
Invalid
Fred\ [email protected]
Invalid
Joe.\\[email protected]
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()[email protected]
Valid
first.(&#13;&#10; middle&#13;&#10; )[email protected]
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)[email protected]
Invalid
first(abc.def)[email protected]
Valid
first(a"bc.def)[email protected]
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
[email protected]
Valid
.@
Invalid
a@b
Valid
@bar.com
Invalid
@@bar.com
Invalid
[email protected]
Valid
aaa.com
Invalid
[email protected]
Invalid
[email protected]
Invalid
aaa@[123.123.123.123]
Valid
aaa@[123.123.123.123]a
Invalid
aaa@[123.123.123.333]
Invalid
[email protected].
Invalid
a@bar
Valid
[email protected]
Valid
[email protected]
Valid
[email protected]
Valid
[email protected]
Invalid
[email protected]
Invalid
[email protected]
Invalid
[email protected]
Invalid
[email protected]
Valid
"hello my name is"@stutter.com
Valid
"Test \"Fail\" Ing"@iana.org
Valid
[email protected]
Valid
[email protected]
Invalid
[email protected]
Valid
[email protected]
Invalid
[email protected]
Valid
"Joe\\Blow"@iana.org
Valid
Invalid \&#10; Folding \&#10; [email protected]
Invalid
HM2Kinsists@(that comments are allowed)this.is.ok
Valid
user%[email protected]
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; [email protected]
Valid
test.&#13;&#10;&#13;&#10; [email protected]
Invalid
"Unicode NULL \␀"@char.com
Valid
"Unicode NULL ␀"@char.com
Invalid
Unicode NULL \␀@char.com
Invalid
cdburgess+!#$%&'*-/=?+_{}|[email protected]
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
[email protected]
Valid
[email protected]&#10;
Invalid
[email protected]
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