4
^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))
    @((\[[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,}))$

我只能理解正则表达式的一部分,但不能理解整个表达式,比如

([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)

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

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

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

4

3 回答 3

5

干得好:

^(
    (
        [^<>()[\]\\.,;:\s@\"]+ // Disallow these characters any amount of times
        (
            \. // Allow dots
            [^<>()[\]\\.,;:\s@\"]+ // 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
    )
)$
于 2013-05-02T18:25:19.140 回答
5

这是来自 debuggex.com 的易于查看的插图

第一组

第二组

于 2013-05-02T18:27:01.303 回答
4

“不知道这是[\]\\ 什么\s@\"意思”

\]是否已转义]
\\是否已转义\
\s是否任何空白
@是否@
\"已转义"

“+是什么意思”

+表示前面的“一个或多个”+

于 2013-05-02T18:19:12.300 回答