re = /^(?![^a-zA-Z0-9])(?:(?![.]{2,})[a-zA-Z0-9_\-.])+(?<![.])@(?:(?![^a-zA-Z0-9])(?:[a-zA-Z0-9_\-])+(?<![^a-zA-Z0-9])\.)+[a-zA-Z]{2,}$/m
str = 'email@example.com
email@111.222.333.fr
firstname.lastname@example.com
email@subdomain.example.com
123@gmail.com
123@51gmail62548.com
1234567890@example.com
a.defosseux@tbs-education.fr
email@example-one.com
email@example.name
email@example.museum
email@example.co.jp
firstname-lastname@example.com
test@test.com
ezf@aezf.fr.en
azer123@123.fr
a@a.bb
a@a.ccc
a@bb.bb
a.a@bb.bb
a.a.a@bb.bb
a.a.a@a.bb.bb
a.a.a.a@a.a.bb
a.a.a.a@a.bb.bb
a.a.a.a@a.bb.ccc
a.bb.a.a@a.bb.ccc
a--a.a@a.bb.ccc
a.defosseux@tbs-education.x.fr
a.defosseux@tbs-education.x.y.fr
a.defosseux@tbs-education.x-e.y.fr
email@example-one.com
ema.il@example.com
e.ma.il@example.com
ema-il@example.com
e-ma-il@example.com
ema--il@example.com
em_ail@example.com
em__ail@example.com
6email@example.com
email6@example.com
6email6@example.com
test-test@x.fr
tes-t-test@x.fr
yasmina.achak@e.rascol.net
yasmina.achak@e.rascol.net.aezr.azerz.azer.azreezr.azeraez.azer
yasmina.achak@e.rascol.barce
yasmina.achak@e.rascol.bar
yasmina.achak@e.ba
sarah_benabdell@yahoo.fr
sarah__benabdellah@yahoo.fr
sarah---benabdellah@yahoo.fr
sarah___---benabdellah@yahoo.fr
marieagnes.paul@off---white.com
a.a@bb--bb.ccc
a.a@bb--bb.a.ccc
a_a@a.bb
a_a@a.bb
email-@example.com
email_@example.com
a_@a.bb
a._@a.bb
a@ccc
#@%^%#$@#$@#.com
@example.com
Joe Smith <email@example.com>
email.example.com
email@example@example.com
email.@example.com
email..email@example.com
あいうえお@example.com
email@example.com (Joe Smith)
email@example
email@-example.com
email@111.222.333.44444
email@example..com
a..reds@free.fr
Abc..123@example.com
”(),:;<>[\\]@example.com
just”not”right@example.com
this\\ is"really"not\\allowed@example.com
firstname+lastname@example.com
email@123.123.123.123
email@[123.123.123.123]
"email"@example.com
_______@example.com
much."more\\ unusual"@example.com
very.unusual.”@”.unusual.com@example.com
very.”(),:;<>[]”.VERY.”very@\\\\ "very”.unusual@strange.example.com
azer aezr@test.com
zaetazfe.faezf
af@ezfezf
ez#!~f@aezf.fr
azefé@test.com
aze@zaé.com
a@a.a
a.a@a.a
a.a@a.a.a
a.a.a.a@a.a.a
a.a.a.a@a.a.a.a
a..a.a@a.bb.ccc
a.é@b.fr
azer.@fr
.azer@fr
a.defosseux@tbs-education-.fr
a.defosseux@-tbs-education.fr
a.defosseux@-tbs-education-.fr
a.defosseux@1234tbs-education.-x-.fr
.email@example.com
.email.@example.com
email.@example.com
ema..il@example.com
-email@example.com
-email-@example.com
_email@example.com
_email_@example.com
_em_ail_@example.com
_em__ail_@example.com
yaémina.achak@e.rascol.net
.-y__as-min-.@eerez.fr
yasmina.achak@e.b
yasmina.achak@e....bar
_a_@a.bb
_a@a.bb
_.a@a.bb
_.a._@a.bb
a@_a.bb
a@a_.bb
a@_a_.bb
a@a._bb_.ccc
a@a.__a__a__.ccc
a@a.__.bb.ccc'
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
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 Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html