-1

According to this article (almost at the end of it), using the following regex will validate any email under the RFC 5322

But it doesn't work at all. Does anyone can check what the mistake is in this expression please?

A(?=[a-z0-9@.!#$%&'*+/=?^_`{|}~-]{6,254}\z)
  (?=[a-z0-9!#$%&'*+/=?^_`{|}~-]{1,64}@)
  [a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*
@ (?:(?=[a-z0-9-]{1,63}\.)[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+
  (?=[a-z0-9-]{1,63}\z)[a-z0-9](?:[a-z0-9-]*[a-z0-9])?

I tried using regex101.com or others testers but I cannot make it work.

Maximus Decimus
  • 4,901
  • 22
  • 67
  • 95
  • *The reason **you shouldn't use this regex** is that it is overly broad.* – Wiktor Stribiżew Feb 15 '16 at 17:30
  • I would recommend to use a simple regex like `^[^@]+@[^@]+\.[^@]+$` and sent out a validation email to ensure the correctness of the email. This regex just checks if the input string has only one @, at least one character before the @, before the period and after it:http://stackoverflow.com/questions/742451/what-is-the-simplest-regular-expression-to-validate-emails-to-not-accept-them-bl – Alex Feb 15 '16 at 17:35

1 Answers1

0

Use WinMerge* to compare your version and the version from the article. The differences should be clear :)

You've missed a \ from the start, and a \z from the end.

\A(?=[a-z0-9@.!#$%&'*+/=?^_`{|}~-]{6,254}\z)
  (?=[a-z0-9!#$%&'*+/=?^_`{|}~-]{1,64}@)
  [a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*
@ (?:(?=[a-z0-9-]{1,63}\.)[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+
  (?=[a-z0-9-]{1,63}\z)[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\z

*other diff tools are available

RB.
  • 36,301
  • 12
  • 91
  • 131