Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8
  • .NET 7.0 (C#)
  • Rust
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests

Tools

Sponsors
There are currently no sponsors. Become a sponsor today!
An explanation of your regex will be automatically generated as you type.
Detailed match information will be displayed here automatically.
  • All Tokens
  • Common Tokens
  • General Tokens
  • Anchors
  • Meta Sequences
  • Quantifiers
  • Group Constructs
  • Character Classes
  • Flags/Modifiers
  • Substitution
  • A single character of: a, b or c
    [abc]
  • A character except: a, b or c
    [^abc]
  • A character in the range: a-z
    [a-z]
  • A character not in the range: a-z
    [^a-z]
  • A character in the range: a-z or A-Z
    [a-zA-Z]
  • Any single character
    .
  • Alternate - match either a or b
    a|b
  • Any whitespace character
    \s
  • Any non-whitespace character
    \S
  • Any digit
    \d
  • Any non-digit
    \D
  • Any word character
    \w
  • Any non-word character
    \W
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • Zero or one of a
    a?
  • Zero or more of a
    a*
  • One or more of a
    a+
  • Exactly 3 of a
    a{3}
  • 3 or more of a
    a{3,}
  • Between 3 and 6 of a
    a{3,6}
  • Start of string
    ^
  • End of string
    $
  • A word boundary
    \b
  • Non-word boundary
    \B

Regular Expression

/
/
gm

Test String

Code Generator

Generated Code

import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = "^(?<fullAddress>(?<mailbox>([a-zA-Z0-9\\+\\!\\#\\$\\%\\&\\'\\*\\-\\/\\=\\?\\+\\_\\{\\}\\|\\~]|(?<singleDot>(?<!\\.)(?<!^)\\.(?!\\.))|(?<foldedWhiteSpace>\\s?\\&\\#13\\;\\&\\#10\\;.)){1,64})\\s?(?<singleAt>(?<!\\@)(?<!\\-)(?<!\\.)\\@(?!\\@))(?<domain>(?<dns>[[:alnum:]]([[:alnum:]\\-]{0,63}\\.){1,24}[[:alnum:]\\-]{1,63}[[:alnum:]])|(?<IPv4>\\[((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\])|(?<IPv6Full>(\\[IPv6(\\:[0-9a-fA-F]{1,4}){8}\\]))|(?<IPv6Comp1>\\[IPv6\\:((([0-9a-fA-F]{1,4})\\:){1,3}(\\:([0-9a-fA-F]{1,4})){1,5}?\\])|\\[IPv6\\:((([0-9a-fA-F]{1,4})\\:){1,5}(\\:([0-9a-fA-F]{1,4})){1,3}?\\]))|(?<IPv6Comp2>(\\[IPv6\\:\\:(\\:[0-9a-fA-F]{1,4}){1,6}\\]))|(?<IPv6Comp3>(\\[IPv6\\:([0-9a-fA-F]{1,4}\\:){1,6}\\:\\]))|(?<IPv6Comp4>(\\[IPv6\\:\\:\\:)\\])|(?<IPv6v4Full>(\\[IPv6(\\:[0-9a-fA-F]{1,4}){6}\\:((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3})(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\])|(?<IPv6v4Comp1>\\[IPv6\\:((([0-9a-fA-F]{1,4})\\:){1,3}(\\:([0-9a-fA-F]{1,4})){1,5}?(\\:((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))\\])|\\[IPv6\\:((([0-9a-fA-F]{1,4})\\:){1,5}(\\:([0-9a-fA-F]{1,4})){1,3}?(\\:((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))\\]))|(?<IPv6v4Comp2>(\\[IPv6\\:\\:(\\:[0-9a-fA-F]{1,4}){1,5}(\\:((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))\\]))|(?<IPv6v4Comp3>(\\[IPv6\\:([0-9a-fA-F]{1,4}\\:){1,5}\\:(((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))\\]))|(?<IPv6v4Comp4>(\\[IPv6\\:\\:\\:((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3})(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\])))"; final String string = "Valid (as per futility) addresses that I agree are valid\n" + "========================================================\n" + "_somename@iana.org test62 Valid\n" + "_Yosemite.Sam@iana.org test128 Valid\n" + "!def!xyz%abc@iana.org test61 Valid\n" + "{_test_}@iana.org test90 Valid\n" + "+1~1+@iana.org test89 Valid\n" + "~@iana.org test129 Valid\n" + "$A12345@iana.org test60 Valid\n" + "1234567890@iana.org test85 Valid\n" + "1234567890123456789012345678901234567890123456789012345678@12345678901234567890123456789012345678901234567890123456789.12345678901234567890123456789012345678901234567890123456789.123456789012345678901234567890123456789012345678901234567890123.iana.org test9 Valid\n" + "1234567890123456789012345678901234567890123456789012345678901234@iana.org test2 Valid\n" + "a-b@bar.com test202 Valid\n" + "a@b.co-foo.uk test209 Valid\n" + "a@bar.com test193 Valid\n" + "aaa@[123.123.123.123] test197 Valid\n" + "cdburgess+!#$%&'*-/=?+_{}|~test@gmail.com test229 Valid\n" + "customer/department@iana.org test127 Valid\n" + "customer/department=shipping@iana.org test59 Valid\n" + "dclo@us.ibm.com test63 Valid\n" + "first.last @iana.org test223 Valid\n" + "first.last@[12.34.56.78] test10 Valid\n" + "first.last@[IPv6:::] test233 Valid\n" + "first.last@[IPv6:::1111:2222:3333:4444:5555:6666] test14 Valid\n" + "first.last@[IPv6:::12.34.56.78] test11 Valid\n" + "first.last@[IPv6:::a2:a3:a4:b1:ffff:11.22.33.44] test252 Valid\n" + "first.last@[IPv6:::a3:a4:b1:ffff:11.22.33.44] test251 Valid\n" + "first.last@[IPv6:1111:2222:3333::4444:5555:6666:7777] test45 Valid\n" + "first.last@[IPv6:::b3:b4] test239 Valid\n" + "first.last@[IPv6:::b4] test236 Valid\n" + "first.last@[IPv6:0123:4567:89ab:cdef::] test249 Valid\n" + "first.last@[IPv6:0123:4567:89ab:CDEF::] test250 Valid\n" + "first.last@[IPv6:0123:4567:89ab:cdef::11.22.33.44] test262 Valid\n" + "first.last@[IPv6:0123:4567:89ab:CDEF::11.22.33.44] test264 Valid\n" + "first.last@[IPv6:1111:2222:3333::4444:12.34.56.78] test12 Valid\n" + "first.last@[IPv6:1111:2222:3333::4444:5555:12.34.56.78] test38 Valid\n" + "first.last@[IPv6:1111:2222:3333::4444:5555:6666] test15 Valid\n" + "first.last@[IPv6:1111:2222:3333:4444:5555:6666::] test16 Valid\n" + "first.last@[IPv6:1111:2222:3333:4444:5555:6666:12.34.56.78] test13 Valid\n" + "first.last@[IPv6:1111:2222:3333:4444:5555:6666:7777:8888] test17 Valid\n" + "first.last@[IPv6:a1::] test244 Valid\n" + "first.last@[IPv6:a1::11.22.33.44] test258 Valid\n" + "first.last@[IPv6:a1::b2:11.22.33.44] test270 Valid\n" + "first.last@[IPv6:a1::b4] test241 Valid\n" + "first.last@[IPv6:a1:a2::] test247 Valid\n" + "first.last@[IPv6:a1:a2::11.22.33.44] test260 Valid\n" + "first.last@[IPv6:a1:a2:a3:a4::11.22.33.44] test253 Valid\n" + "first.last@[IPv6:a1:a2:a3:a4:b1::11.22.33.44] test254 Valid\n" + "first.last@123.iana.org test20 Valid\n" + "first.last@3com.com test19 Valid\n" + "first.last@example.123 test48 Valid\n" + "first.last@iana.org test1 Valid\n" + "first.last@x23456789012345678901234567890123456789012345678901234567890123.iana.org test18 Valid\n" + "foobar@192.168.0.1 test216 Valid\n" + "Ima.Fool@iana.org test135 Valid\n" + "name.lastname@domain.com test188 Valid\n" + "peter.piper@iana.org test66 Valid\n" + "shaitan@my-domain.thisisminekthx test214 Valid\n" + "t*est@iana.org test88 Valid\n" + "test-test@iana.org test87 Valid\n" + "test. &#13;&#10; &#13;&#10; obs@syntax.com test224 Valid\n" + "Test.&#13;&#10; Folding.&#13;&#10; Whitespace@iana.org test152 Valid\n" + "test.test@iana.org test92 Valid\n" + "test@[123.123.123.123] test98 Valid\n" + "test@123.123.123.123 test97 Valid\n" + "test@123.123.123.x123 test96 Valid\n" + "test@example.example.iana.org test100 Valid\n" + "test@example.iana.org test99 Valid\n" + "test@iana.org test83 Valid\n" + "TEST@iana.org test84 Valid\n" + "test@test.com test277 Valid\n" + "test@xn--example.com test279 Valid\n" + "test+test@iana.org test86 Valid\n" + "user%uucp!path@berkeley.edu test220 Valid\n" + "user+mailbox@iana.org test58 Valid\n" + "valid@about.museum test212 Valid\n\n" + "Valid (as per futility) addresses that are invalid as per RFC5321\n" + "============================================================================\n" + "+@b.c test203 Valid\n" + "first.last@com test49 Valid\n" + "a@b test190 Valid\n" + "a@bar test201 Valid\n" + "test@Bücher.ch test280 Valid\n" + "test@example test116 Valid\n" + "first.last@[IPv6:::a2:a3:a4:b1:b2:b3:b4] test230 Valid\n" + "first.last@[IPv6:a1:a2:a3:a4:b1:b2:b3::] test231 Valid\n" + "+@b.com test204 Valid\n\n" + "My tests for valid IPv6 and v6v4 addresses\n" + "==========================================\n" + "first.last@[IPv6:1111:2222:3333:4444:5555:6666:7777:8888]\n" + "first.last@[IPv6:1111:2222:3333:4444:5555:6666:12.34.56.78]\n\n" + "first.last@[IPv6:1111:2222:3333:4444:5555:6666::]\n" + "first.last@[IPv6:1111:2222:3333:4444:5555::8888]\n" + "first.last@[IPv6:1111:2222:3333:4444::7777:8888]\n" + "first.last@[IPv6:1111:2222:3333::6666:7777:8888]\n" + "first.last@[IPv6:1111:2222::5555:6666:7777:8888]\n" + "first.last@[IPv6:1111::4444:5555:6666:7777:8888]\n" + "first.last@[IPv6:::3333:4444:5555:6666:7777:8888]\n" + "first.last@[IPv6:1111:2222:3333:4444:5555::]\n" + "first.last@[IPv6:1111:2222:3333:4444::8888]\n" + "first.last@[IPv6:1111:2222:3333::7777:8888]\n" + "first.last@[IPv6:1111:2222::6666:7777:8888]\n" + "first.last@[IPv6:1111::5555:6666:7777:8888]\n" + "first.last@[IPv6:::4444:5555:6666:7777:8888]\n" + "first.last@[IPv6:::3333:4444:5555:6666:7777:8888]\n" + "first.last@[IPv6:1111:2222:3333:4444::12.34.56.78]\n" + "first.last@[IPv6:1111:2222:3333::6666:12.34.56.78]\n" + "first.last@[IPv6:1111:2222::5555:6666:12.34.56.78]\n" + "first.last@[IPv6:1111::4444:5555:6666:12.34.56.78]\n" + "first.last@[IPv6:::3333:4444:5555:6666:12.34.56.78]\n\n\n" + "Invalid (as per futility) addresses with valid mailbox defective domain\n" + "=======================================================================\n" + "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 test8 Valid\n" + "123456789012345678901234567890123456789012345678901234567890@12345678901234567890123456789012345678901234567890123456789.12345678901234567890123456789012345678901234567890123456789.12345678901234567890123456789012345678901234567890123456789.12345.iana.org test21 Invalid\n" + "first.last@[IPv6:1111:2222:33333::7777:8888] test47 Invalid\n" + "aaa@[123.123.123.123]a test198 Invalid\n" + "a@b-.com test206 Invalid\n" + "a@bar.com. test200 Invalid\n" + "a@-b.com test205 Invalid\n" + "aaa@.123 test196 Invalid\n" + "aaa@.com test195 Invalid\n" + "aaa@[123.123.123.333] test199 Invalid\n" + "abc@def@iana.org test69 Invalid\n" + "doug@ test73 Invalid\n" + "first.last@ test33 Invalid\n" + "first.last@-xample.com test50 Invalid\n" + "first.last@[::12.34.56.78] test37 Invalid\n" + "first.last@[.12.34.56.78] test35 Invalid\n" + "first.last@[12.34.56.789] test36 Invalid\n" + "first.last@[IPv5:::12.34.56.78] test37 Invalid\n" + "first.last@[IPv6::::] test234 Invalid\n" + "first.last@[IPv6::::11.22.33.44] test256 Invalid\n" + "first.last@[IPv6::::b3:b4] test240 Invalid\n" + "first.last@[IPv6::::b4] test237 Invalid\n" + "first.last@[IPv6::] test232 Invalid\n" + "first.last@[IPv6::11.22.33.44] test255 Invalid\n" + "first.last@[IPv6::a2::b4] test273 Invalid\n" + "first.last@[IPv6::a2:a3:a4:b1:b2:b3:b4] test275 Invalid\n" + "first.last@[IPv6::b3:b4] test238 Invalid\n" + "first.last@[IPv6::b4] test235 Invalid\n" + "first.last@[IPv6:0123:4567:89ab:cdef::11.22.33.xx] test263 Invalid\n" + "first.last@[IPv6:0123:4567:89ab:CDEFF::11.22.33.44] test265 Invalid\n" + "first.last@[IPv6:1111:2222::3333::4444:5555:6666] test44 Invalid\n" + "first.last@[IPv6:1111:2222:3333:4444:5555:12.34.56.78] test40 Invalid\n" + "first.last@[IPv6:1111:2222:3333:4444:5555:6666:12.34.567.89] test158 Invalid\n" + "first.last@[IPv6:1111:2222:3333:4444:5555:6666:7777:12.34.56.78] test41 Invalid\n" + "first.last@[IPv6:1111:2222:3333:4444:5555:6666:7777:8888:9999] test43 Invalid\n" + "first.last@[IPv6:1111:2222:3333:4444:5555:6666:7777] test42 Invalid\n" + "first.last@[IPv6:1111:2222:333x::4444:5555] test46 Invalid\n" + "first.last@[IPv6:a1:::] test245 Invalid\n" + "first.last@[IPv6:a1:::11.22.33.44] test259 Invalid\n" + "first.last@[IPv6:a1:::b4] test242 Invalid\n" + "first.last@[IPv6:a1::11.22.33.44.55] test268 Invalid\n" + "first.last@[IPv6:a1::11.22.33] test267 Invalid\n" + "first.last@[IPv6:a1::a4:b1::b4:11.22.33.44] test266 Invalid\n" + "first.last@[IPv6:a1::b2::11.22.33.44] test271 Invalid\n" + "first.last@[IPv6:a1::b211.22.33.44] test269 Invalid\n" + "first.last@[IPv6:a1::b3:] test272 Invalid\n" + "first.last@[IPv6:a1:] test243 Invalid\n" + "first.last@[IPv6:a1:11.22.33.44] test257 Invalid\n" + "first.last@[IPv6:a1:a2:::] test248 Invalid\n" + "first.last@[IPv6:a1:a2:::11.22.33.44] test261 Invalid\n" + "first.last@[IPv6:a1:a2:] test246 Invalid\n" + "first.last@[IPv6:a1:a2:a3:a4::b1:b2:b3:b4] test276 Invalid\n" + "first.last@[IPv6:a1:a2:a3:a4:b1:b2:b3:] test274 Invalid\n" + "first.last@exampl-.com test51 Invalid\n" + "first.last@sub.do,com test3 Invalid\n" + "first.last@x234567890123456789012345678901234567890123456789012345678901234.iana.org test52 Invalid\n" + "foo@[\\1.2.3.4] test149 Invalid\n" + "gatsby@f.sc.ot.t.f.i.tzg.era.l.d. test82 Invalid\n" + "Invalid@about.museum- test213 Invalid\n" + "test@[123.123.123.123 test117 Invalid\n" + "test@@iana.org test106 Invalid\n" + "test@123.123.123.123] test118 Invalid\n" + "test@123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012.com test115 Invalid\n" + "test@example. test113 Invalid\n" + "test@example.com&#10; test278 Invalid\n" + "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 test34 Invalid\n\n\n" + "Invalid (as per futility) addresses with valid domain defective mailbox\n" + "=======================================================================\n" + "-- test --@iana.org test107 Invalid\n" + ".@iana.org test133 Invalid\n" + ".dot@iana.org test76 Invalid\n" + ".first.last@iana.org test24 Invalid\n" + ".test@iana.org test104 Invalid\n" + ".wooly@iana.org test130 Invalid\n" + "()[]\\;:,><@iana.org test111 Invalid\n" + "[test]@iana.org test108 Invalid\n" + "{^c\\@**Dog^}@cartoon.com test161 Invalid\n" + "@iana.org test72 Invalid\n" + "12345678901234567890123456789012345678901234567890123456789012345@iana.org test23 Invalid\n" + "Abc\\@def@iana.org test155 Invalid\n" + "abc\\@def@iana.org test64 Invalid\n" + "abc\\@iana.org test71 Invalid\n" + "abc\\\\@def@iana.org test70 Invalid\n" + "abc\\\\@iana.org test65 Invalid\n" + "dot.@iana.org test77 Invalid\n" + "first..last@iana.org test26 Invalid\n" + "first.last.@iana.org test25 Invalid\n" + "first(12345678901234567890123456789012345678901234567890)last@(1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890)iana.org test173 Invalid\n" + "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) test183 Invalid\n" + "first(middle)last@iana.org test179 Invalid\n" + "first\\@last@iana.org test5 Invalid\n" + "first\\\\@last@iana.org test32 Invalid\n" + "first\\last@iana.org test154 Invalid\n" + "Fred\\ Bloggs@iana.org test156 Invalid\n" + "hello world@iana.org test81 Invalid\n" + "Ima Fool@iana.org test138 Invalid\n" + "Invalid \\&#10; Folding \\&#10; Whitespace@iana.org test218 Invalid\n" + "Joe.\\\\Blow@iana.org test157 Invalid\n" + "NotAnEmail test119 Invalid\n" + "ote\\\"@iana.org test75 Invalid\n" + "phil.h\\@\\@ck@haacked.com test139 Invalid\n" + "pootietang.@iana.org test132 Invalid\n" + "test..test@iana.org test103 Invalid\n" + "test.@iana.org test102 Invalid\n" + "test.&#13;&#10;&#13;&#10; obs@syntax.com test225 Invalid\n" + "test.iana.org test101 Invalid\n" + "test@. test112 Invalid\n" + "test@...........com test215 Invalid\n" + "test@.org test114 Invalid\n" + "test@test@iana.org test105 Invalid\n" + "two..dot@iana.org test78 Invalid\n" + "Unicode NULL \\\\\\u0000@char.com test228 Invalid\n" + "wo..oly@iana.org test131 Invalid\n\n\n" + "Invalid (as per futility) addresses with defective mailbox and domain\n" + "=======================================================================\n" + "-- test --@iana.org test107 Invalid\n" + "-@..com test207 Invalid\n" + "-@a..com test208 Invalid\n" + ".@ test189 Invalid\n" + "@@bar.com test192 Invalid\n" + "@bar.com test191 Invalid\n" + "@NotAnEmail test120 Invalid\n" + "aaa.com test194 Invalid\n" + "first.last test22 Invalid\n\n\n" + "Valid (as per futility) addresses that use parenthesis or quotes\n" + "================================================================\n" + "&#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 test222 Valid\n" + "1234 @ local(blah) .machine .example test178 Valid\n" + "a(a(b(c)d(e(f))g)h(i)j)@iana.org test186 Valid\n" + "c@(Chris's host.)public.example test176 Valid\n" + "cal(foo\\)bar)@iamcal.com test167 Valid\n" + "cal(foo\\@bar)@iamcal.com test166 Valid\n" + "cal(woo(yay)hoopla)@iamcal.com test165 Valid\n" + "cal@iamcal(woo).(yay)com test163 Valid\n" + "first.last@x(1234567890123456789012345678901234567890123456789012345678901234567890).com test185 Valid\n" + "HM2Kinsists@(that comments are allowed)this.is.ok test219 Valid\n" + "jdoe@machine(comment). example test177 Valid\n" + "first.(\\\")middle.last(\\\")@iana.org test182 Valid\n" + "first.(&#13;&#10; middle&#13;&#10; )last@iana.org test172 Valid\n" + "first.\\\"last\\\"@iana.org test144 Valid\n" + "first.\\\"mid\\\\dle\\\".\\\"last\\\"@iana.org test151 Valid\n" + "first(Welcome to&#13;&#10; the (\\\"wonderful\\\" (!)) world&#13;&#10; of email)@iana.org test174 Valid\n" + "pete(his account)@silly.test(his host) test175 Valid\n" + "first().last@iana.org test171 Valid\n" + "first(a\\\"bc.def).last@iana.org test181 Valid\n" + "first(abc.def).last@iana.org test180 Valid\n" + "first(abc\\(def)@iana.org test184 Valid\n" + "first().last@iana.org test171 Valid\n" + "first(a\\\"bc.def).last@iana.org test181 Valid\n" + "first(abc.def).last@iana.org test180 Valid\n" + "first(abc\\(def)@iana.org test184 Valid\n" + "(foo)cal(bar)@(baz)iamcal.com(quux) test162 Valid\n" + "test.\\\"test\\\"@iana.org test94 Valid\n" + "\"\\\"Unicode NULL \\\\\\u0000\\\"@char.com test226 Valid\n" + "\\\"[[ test ]]\\\"@iana.org test91 Valid\n" + "\\\"Abc@def\\\"@iana.org test56 Valid\n" + "\\\"Abc\\\\@def\\\"@iana.org test53 Valid\n" + "\\\"Austin@Powers\\\"@iana.org test134 Valid\n" + "\\\"Doug \\\\\\\"Ace\\\\\\\" L.\\\"@iana.org test68 Valid\n" + "\\\"first..last\\\"@iana.org test148 Valid\n" + "\\\"first.middle.last\\\"@iana.org test147 Valid\n" + "\\\"first.middle\\\".\\\"last\\\"@iana.org test146 Valid\n" + "\\\"first(last)\\\"@iana.org test221 Valid\n" + "\\\"first@last\\\"@iana.org test6 Valid\n" + "\\\"first\\\".\\\"last\\\"@iana.org test140 Valid\n" + "\\\"first\\\".\\\"middle\\\".\\\"last\\\"@iana.org test145 Valid\n" + "\\\"first\\\".last@iana.org test143 Valid\n" + "\\\"first\\\".middle.\\\"last\\\"@iana.org test141 Valid\n" + "\\\"first\\\\\\\"last\\\"@iana.org test4 Valid\n" + "\\\"first\\\\\\\\\\\\\\\"last\\\"@iana.org test150 Valid\n" + "\\\"first\\\\\\\\last\\\"@iana.org test7 Valid\n" + "\\\"first\\\\last\\\"@iana.org test28 Valid\n" + "\\\"Fred Bloggs\\\"@iana.org test57 Valid\n" + "\\\"Fred\\\\ Bloggs\\\"@iana.org test54 Valid\n" + "\\\"hello my name is\\\"@stutter.com test210 Valid\n" + "\\\"Ima Fool\\\"@iana.org test137 Valid\n" + "\\\"Ima.Fool\\\"@iana.org test136 Valid\n" + "\\\"Joe.\\\\\\\\Blow\\\"@iana.org test55 Valid\n" + "\\\"Joe\\\\\\\\Blow\\\"@iana.org test217 Valid\n" + "\\\"Test \\\\\\\"Fail\\\\\\\" Ing\\\"@iana.org test211 Valid\n" + "\\\"test.test\\\"@iana.org test93 Valid\n" + "\\\"test@test\\\"@iana.org test95 Valid\n" + "\\\"test\\\\\\\"blah\\\"@iana.org test125 Valid\n" + "\\\"test\\\\\\\\blah\\\"@iana.org test121 Valid\n" + "\\\"test\\\\&#13;blah\\\"@iana.org test123 Valid\n" + "\\\"test\\\\blah\\\"@iana.org test122 Valid\n" + "\\\"test\\\\test\\\"@iana.org test109 Valid\n" + "\\\"test&#13;&#10; blah\\\"@iana.org test160 Valid\n\n\n" + "Invalid (as per futility) addresses that use parenthesis or quotes\n" + "==================================================================\n" + "\\\"\\\"@iana.org test31 Invalid\n" + "\\\"\\\"\\\"@iana.org test29 Invalid\n" + "\\\"\\\\\\\"@iana.org test30 Invalid\n" + "\\\"Doug \\\"Ace\\\" L.\\\"@iana.org test79 Invalid\n" + "\\\"first\\\"last\\\"@iana.org test27 Invalid\n" + "\\\"first\\\\\\\\\\\"last\\\"@iana.org test142 Invalid\n" + "\\\"foo\\\"(yay)@(hoopla)[1.2.3.4] test164 Invalid\n" + "\\\"qu@iana.org test74 Invalid\n" + "\\\"test\\\"blah\\\"@iana.org test126 Invalid\n" + "\\\"test\\\"test\\\"@iana.org test110 Invalid\n" + "\\\"test\\&#13;&#10; blah\\\"@iana.org test159 Invalid\n" + "\\\"test&#13;blah\\\"@iana.org test124 Invalid\n" + "\\\"Unicode NULL \\u0000\\\"@char.com test227 Invalid\n" + "a(a(b(c)d(e(f))g)(h(i)j)@iana.org test187 Invalid\n" + "cal(foo(bar)@iamcal.com test168 Invalid\n" + "cal(foo)bar)@iamcal.com test196 Invalid\n" + "cal(foo\\)@iamcal.com test170 Invalid\n" + "Doug\\\\ \\\\\\\"Ace\\\\\\\"\\\\ L\\\\.@iana.org test80 Invalid\n" + "Doug\\\\ \\\\\\\"Ace\\\\\\\"\\\\ Lovell@iana.org test67 Invalid\n" + "first.\\\"\\\".last@iana.org test153 Invalid"; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); final Matcher matcher = pattern.matcher(string); while (matcher.find()) { System.out.println("Full match: " + matcher.group(0)); for (int i = 1; i <= matcher.groupCount(); i++) { System.out.println("Group " + i + ": " + matcher.group(i)); } } } }

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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html