2013-05-02 88 views
4
^(([^<>()[\]\\.,;:\[email protected]\"]+(\.[^<>()[\]\\.,;:\[email protected]\"]+)*)|(\".+\")) 
    @((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.) 
    +[a-zA-Z]{2,}))$ 

我只能理解正则表达式的部分,但不是全部的表情,像有人能解释这个电子邮件正则表达式意味着

([^<>()[\]\\.,;:\[email protected]\"]+(\.[^<>()[\]\\.,;:\[email protected]\"]+)*)

匹配一个或多个字符的不是人物

<>()[\]\\.,;:\[email protected]\" \\ Not sure what this [\]\\ and \[email protected]\ means 

我可以理解一些其他部分,但不能作为一个单一的实体。

+0

你从哪里得到的?它是一个传递给'new RegExp'的字符串,还是你忽略了文字分隔符? – Bergi 2013-05-02 18:14:23

+0

我正在使用JavaScript验证,并且遇到它它被用来测试'电子邮件地址'我试图理解它,但徒劳无功 – 2013-05-02 18:16:23

+0

http://www.myezapp.com/apps/dev/regexp/show .ws将其插入此处以便捕获组等的视觉分析。这里是你的:http://tinyurl.com/ccuqrwk – asawyer 2013-05-02 18:16:34

回答

5

什么先在这里你去:

^(
    (
     [^<>()[\]\\.,;:\[email protected]\"]+ // Disallow these characters any amount of times 
     (
      \. // Allow dots 
      [^<>()[\]\\.,;:\[email protected]\"]+ // Disallow these characters any amount of times 
     )* // This group must occur once or more 
    ) 
    | // or 
    (\".+\") // Anything surrounded by quotes (Is this even legal?) 
) 
@ // At symbol is litterally that 
(
    // IP address 
    (
     \[ // Allows square bracket 
     [0-9]{1,3} // 1 to three digits (for an IP address 
     \. // Allows dot 
     [0-9]{1,3} // 1 to three digits (for an IP address 
     \. // Allows dot 
     [0-9]{1,3} // 1 to three digits (for an IP address 
     \. // Allows dot 
     [0-9]{1,3} // 1 to three digits (for an IP address 
     \] // Square bracket 
    ) 
    | // OR a domain name 
    (
     ([a-zA-Z\-0-9]+\.) // Valid domain characters are a-zA-Z0-9 plus dashes 
     + 
     [a-zA-Z]{2,} // The top level (anything after the dot) must be at least 2 chars long and only a-zA-Z 
    ) 
)$ 
+0

感谢您的详细解释。 – 2013-05-02 18:42:57

+0

+1非常详尽的答案。 – Orbling 2013-05-02 19:18:46

4

“不知道这是什么[\]\\\[email protected]\"意味着”

\]是逃脱]
\\被转义\
\s是任何空白
@@
\"被转义"

“什么是+意味着”

+意味着“一个或多个”的+

5

下面是一个容易看到debuggex插图。 COM

First group

Second Group

+0

真棒网站!据此,我的姓氏(我无法控制)的撇号电子邮件地址不会通过此正则表达式。 – DOK 2013-05-02 18:50:59

+1

你的图像实际上是关闭的,因为当你复制和粘贴正则表达式时,你会得到一堆OP添加的空白,所以我们不需要双面滚动。尽管酷的网站,书签。这里更新:http://tinyurl.com/cklksdd – smerny 2013-05-02 19:07:06

相关问题