用 Regular Expression 表示合法 e-mail 位置似乎是每隔一陣子就會被拿出來大家笑的東西?
Photo Matt 提到的 Validate Emails:
(?:(?:\r\n)?[ \t])*(?:(?:(?:[^()<>@,;:”.\[\]
\000-\031]+(?:(?:(?:\r\n)?[ \t]
)+|\Z|(?=[\[“()<>@,;:”.\[\]]))|”(?:[^”\r\]|\.|(?:(?:\r\n)?[
\t]))*”(?:(?: \r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[
\t])*(?:[^()<>@,;:”.\[\] \000-\031]+(?:(?:( ?:\r\n)?[
\t])+|\Z|(?=[\[“()<>@,;:”.\[\]]))|”(?:[^”\r\]|\.|(?:(?:\r\n)?[
\t]))*”(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:”.\[\]
\000-\0 31]+(?:(?:(?:\r\n)?[
\t])+|\Z|(?=[\[“()<>@,;:”.\[\]]))|\[([^\[\]\r\]|\.)*\
](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:”.\[\]
\000-\031]+ (?:(?:(?:\r\n)?[
\t])+|\Z|(?=[\[“()<>@,;:”.\[\]]))|\[([^\[\]\r\]|\.)*\](?:
(?:\r\n)?[ \t])*))*|(?:[^()<>@,;:”.\[\] \000-\031]+(?:(?:(?:\r\n)?[
\t])+|\Z |(?=[\[“()<>@,;:”.\[\]]))|”(?:[^”\r\]|\.|(?:(?:\r\n)?[
\t]))*”(?:(?:\r\n) ?[ \t])*)*\<(?:(?:\r\n)?[
\t])*(?:@(?:[^()<>@,;:”.\[\] \000-\031]+(?:(?:(?:\ r\n)?[
\t])+|\Z|(?=[\[“()<>@,;:”.\[\]]))|\[([^\[\]\r\]|\.)*\](?:(?:\r\n)?[
\t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:”.\[\]
\000-\031]+(?:(?:(?:\r\n) ?[
\t])+|\Z|(?=[\[“()<>@,;:”.\[\]]))|\[([^\[\]\r\]|\.)*\](?:(?:\r\n)?[
\t] )*))*(?:,@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:”.\[\]
\000-\031]+(?:(?:(?:\r\n)?[
\t])+|\Z|(?=[\[“()<>@,;:”.\[\]]))|\[([^\[\]\r\]|\.)*\](?:(?:\r\n)?[
\t])* )(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:”.\[\]
\000-\031]+(?:(?:(?:\r\n)?[ \t]
)+|\Z|(?=[\[“()<>@,;:”.\[\]]))|\[([^\[\]\r\]|\.)*\](?:(?:\r\n)?[
\t])*))*) *:(?:(?:\r\n)?[ \t])*)?(?:[^()<>@,;:”.\[\]
\000-\031]+(?:(?:(?:\r\n)?[ \t])+
|\Z|(?=[\[“()<>@,;:”.\[\]]))|”(?:[^”\r\]|\.|(?:(?:\r\n)?[
\t]))*”(?:(?:\r \n)?[ \t])*)(?:\.(?:(?:\r\n)?[
\t])*(?:[^()<>@,;:”.\[\] \000-\031]+(?:(?:(?: \r\n)?[
\t])+|\Z|(?=[\[“()<>@,;:”.\[\]]))|”(?:[^”\r\]|\.|(?:(?:\r\n)?[ \t
]))*”(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:”.\[\]
\000-\031 ]+(?:(?:(?:\r\n)?[
\t])+|\Z|(?=[\[“()<>@,;:”.\[\]]))|\[([^\[\]\r\]|\.)*\](
?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:”.\[\]
\000-\031]+(? :(?:(?:\r\n)?[
\t])+|\Z|(?=[\[“()<>@,;:”.\[\]]))|\[([^\[\]\r\]|\.)*\](?:(?
:\r\n)?[ \t])*))*\>(?:(?:\r\n)?[ \t])*)|(?:[^()<>@,;:”.\[\]
\000-\031]+(?:(? :(?:\r\n)?[
\t])+|\Z|(?=[\[“()<>@,;:”.\[\]]))|”(?:[^”\r\]|\.|(?:(?:\r\n)? [
\t]))*”(?:(?:\r\n)?[ \t])*)*:(?:(?:\r\n)?[
\t])*(?:(?:(?:[^()<>@,;:”.\[\] \000-\031]+(?:(?:(?:\r\n)?[
\t])+|\Z|(?=[\[“()<>@,;:”.\[\]]))|”(?:[^”\r\]| \.|(?:(?:\r\n)?[
\t]))*”(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>
@,;:”.\[\] \000-\031]+(?:(?:(?:\r\n)?[
\t])+|\Z|(?=[\[“()<>@,;:”.\[\]]))|” (?:[^”\r\]|\.|(?:(?:\r\n)?[
\t]))*”(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t] )*(?:[^()<>@,;:”.\[\]
\000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\[“()<>@,;:\
“.\[\]]))|\[([^\[\]\r\]|\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[
\t])*(? :[^()<>@,;:”.\[\] \000-\031]+(?:(?:(?:\r\n)?[
\t])+|\Z|(?=[\[“()<>@,;:”.\[
\]]))|\[([^\[\]\r\]|\.)*\](?:(?:\r\n)?[
\t])*))*|(?:[^()<>@,;:”.\[\] \000- \031]+(?:(?:(?:\r\n)?[
\t])+|\Z|(?=[\[“()<>@,;:”.\[\]]))|”(?:[^”\r\]|\.|( ?:(?:\r\n)?[
\t]))*”(?:(?:\r\n)?[ \t])*)*\<(?:(?:\r\n)?[ \t])*(?:@(?:[^()<>@,;
:”.\[\] \000-\031]+(?:(?:(?:\r\n)?[
\t])+|\Z|(?=[\[“()<>@,;:”.\[\]]))|\[([
^\[\]\r\]|\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[
\t])*(?:[^()<>@,;:” .\[\] \000-\031]+(?:(?:(?:\r\n)?[
\t])+|\Z|(?=[\[“()<>@,;:”.\[\]]))|\[([^\[\
]\r\]|\.)*\](?:(?:\r\n)?[ \t])*))*(?:,@(?:(?:\r\n)?[
\t])*(?:[^()<>@,;:”.\ [\] \000-\031]+(?:(?:(?:\r\n)?[
\t])+|\Z|(?=[\[“()<>@,;:”.\[\]]))|\[([^\[\]\
r\]|\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[
\t])*(?:[^()<>@,;:”.\[\] \000-\031]+(?:(?:(?:\r\n)?[
\t])+|\Z|(?=[\[“()<>@,;:”.\[\]]))|\[([^\[\]\r\]
|\.)*\](?:(?:\r\n)?[ \t])*))*)*:(?:(?:\r\n)?[
\t])*)?(?:[^()<>@,;:”.\[\] \0 00-\031]+(?:(?:(?:\r\n)?[
\t])+|\Z|(?=[\[“()<>@,;:”.\[\]]))|”(?:[^”\r\]|\ .|(?:(?:\r\n)?[
\t]))*”(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,
;:”.\[\] \000-\031]+(?:(?:(?:\r\n)?[
\t])+|\Z|(?=[\[“()<>@,;:”.\[\]]))|”(? :[^”\r\]|\.|(?:(?:\r\n)?[
\t]))*”(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])* (?:[^()<>@,;:”.\[\]
\000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\[“()<>@,;:”.
\[\]]))|\[([^\[\]\r\]|\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[
\t])*(?:[ ^()<>@,;:”.\[\] \000-\031]+(?:(?:(?:\r\n)?[
\t])+|\Z|(?=[\[“()<>@,;:”.\[\]
]))|\[([^\[\]\r\]|\.)*\](?:(?:\r\n)?[ \t])*))*\>(?:(?:\r\n)?[
\t])*)(?:,\s*( ?:(?:[^()<>@,;:”.\[\] \000-\031]+(?:(?:(?:\r\n)?[
\t])+|\Z|(?=[\[“()<>@,;:\ “.\[\]]))|”(?:[^”\r\]|\.|(?:(?:\r\n)?[
\t]))*”(?:(?:\r\n)?[ \t])*)(?:\.(?:( ?:\r\n)?[
\t])*(?:[^()<>@,;:”.\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[
\[“()<>@,;:”.\[\]]))|”(?:[^”\r\]|\.|(?:(?:\r\n)?[
\t]))*”(?:(?:\r\n)?[ \t ])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:”.\[\]
\000-\031]+(?:(?:(?:\r\n)?[ \t
])+|\Z|(?=[\[“()<>@,;:”.\[\]]))|\[([^\[\]\r\]|\.)*\](?:(?:\r\n)?[
\t])*)(? :\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:”.\[\]
\000-\031]+(?:(?:(?:\r\n)?[ \t])+|
\Z|(?=[\[“()<>@,;:”.\[\]]))|\[([^\[\]\r\]|\.)*\](?:(?:\r\n)?[
\t])*))*|(?: [^()<>@,;:”.\[\] \000-\031]+(?:(?:(?:\r\n)?[
\t])+|\Z|(?=[\[“()<>@,;:”.\[\ ]]))|”(?:[^”\r\]|\.|(?:(?:\r\n)?[
\t]))*”(?:(?:\r\n)?[ \t])*)*\<(?:(?:\r\n) ?[
\t])*(?:@(?:[^()<>@,;:”.\[\] \000-\031]+(?:(?:(?:\r\n)?[
\t])+|\Z|(?=[\[”
()<>@,;:”.\[\]]))|\[([^\[\]\r\]|\.)*\](?:(?:\r\n)?[
\t])*)(?:\.(?:(?:\r\n) ?[ \t])*(?:[^()<>@,;:”.\[\]
\000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\[“()<>
@,;:”.\[\]]))|\[([^\[\]\r\]|\.)*\](?:(?:\r\n)?[
\t])*))*(?:,@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:”.\[\]
\000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\[“()<>@,
;:”.\[\]]))|\[([^\[\]\r\]|\.)*\](?:(?:\r\n)?[
\t])*)(?:\.(?:(?:\r\n)?[ \t] )*(?:[^()<>@,;:”.\[\]
\000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\[“()<>@,;:\
“.\[\]]))|\[([^\[\]\r\]|\.)*\](?:(?:\r\n)?[ \t])*))*)*:(?:(?:\r\n)?[
\t])*)? (?:[^()<>@,;:”.\[\] \000-\031]+(?:(?:(?:\r\n)?[
\t])+|\Z|(?=[\[“()<>@,;:”. \[\]]))|”(?:[^”\r\]|\.|(?:(?:\r\n)?[
\t]))*”(?:(?:\r\n)?[ \t])*)(?:\.(?:(?: \r\n)?[
\t])*(?:[^()<>@,;:”.\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\[
“()<>@,;:”.\[\]]))|”(?:[^”\r\]|\.|(?:(?:\r\n)?[
\t]))*”(?:(?:\r\n)?[ \t]) *))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:”.\[\]
\000-\031]+(?:(?:(?:\r\n)?[ \t])
+|\Z|(?=[\[“()<>@,;:”.\[\]]))|\[([^\[\]\r\]|\.)*\](?:(?:\r\n)?[
\t])*)(?:\ .(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:”.\[\]
\000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z
|(?=[\[“()<>@,;:”.\[\]]))|\[([^\[\]\r\]|\.)*\](?:(?:\r\n)?[
\t])*))*\>(?:( ?:\r\n)?[ \t])*))*)?;\s*)
http://search.cpan.org/~cwest/Regexp-Common-Email-Address-1.01/
thanks,只是貼出來讓大家笑而已 :P (每隔一陣子就會被提到的東西)
Mastering Regular Expression 書末也有一個例子,不過我不知道是不是同一個…