繁体   English   中英

有人可以解释这个电子邮件正则表达式的含义

[英]Can someone explain what this Email regex means

^(([^<>()[\]\\.,;:\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

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

干得好:

^(
    (
        [^<>()[\]\\.,;:\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
    )
)$

这是一个来自debuggex.com的简单图解

第一组

第二组

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

\\]是逃脱的]
\\\\是逃脱的\\
\\s是任何空白区域
@@
\\"是逃脱的"

“+意味着什么”

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM