Created
July 4, 2012 00:11
-
-
Save daurnimator/3044300 to your computer and use it in GitHub Desktop.
lpeg email pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local P = lpeg.P | |
local R = lpeg.R | |
local S = lpeg.S | |
local V = lpeg.V | |
local C = lpeg.C | |
local CHAR = R"\0\127" | |
local SPACE = S"\40\32" | |
local CTL = R"\0\31" + P"127" | |
local specials = S[=[()<>@,;:\".[]]=] | |
local atom = (CHAR-specials-SPACE-CTL)^1 | |
local dtext = CHAR - S"[]\\\13" | |
local qtext = CHAR - S'"\\\13' | |
local quoted_pair = "\\" * CHAR | |
local domain_literal = P"[" * ( dtext + quoted_pair )^0 + P"]" | |
local quoted_string = P'"' * ( qtext + quoted_pair )^0 * P'"' | |
local word = atom + quoted_string | |
-- Implements an email "addr-spec" according to RFC822 | |
local email = P { | |
V"addr_spec" ; | |
addr_spec = V"local_part" * P"@" * C(V"domain") ; | |
local_part = word * ( P"." * word )^0 ; | |
domain = V"sub_domain" * ( P"." * V"sub_domain" )^0 ; | |
sub_domain = V"domain_ref" + domain_literal ; | |
domain_ref = atom ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment