I have a large list of emails I am running through. A lot of the emails have typos. I am trying to build a string that will check valid emails.
this is what I have
Yours is complicated indeed.
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
The above code should suffice.
Explanation of each piece of the expression above for clarification:
Start of regex:
/
Match the start of a string:
\A
At least one word character, plus, hyphen, or dot:
[\w+\-.]+
A literal "at sign":
@
A literal dot:
\.
At least one letter:
[a-z]+
Match the end of a string:
\z
End of regex:
/
Case insensitive:
i
Putting it back together again:
/\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
Check out Rubular to conveniently test your expressions as you write them.