简体   繁体   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,}))$

I could only understand parts of the regex but not the entire expression , like 我只能理解正则表达式的部分内容,而不是整个表达式

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

match one or more characters that's are not the characters 匹配一个或多个不是字符的字符

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

I could understand some of the other parts as well but not as a single entity. 我也能理解其他一些部分,但不能理解为单个实体。

Here you go: 干得好:

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

Here is an easy to see illustration from debuggex.com 这是一个来自debuggex.com的简单图解

第一组

第二组

"Not sure what this [\\]\\\\ and \\s@\\" means" “不知道这是什么[\\]\\\\\\s@\\"意思是“

\\] is an escaped ] \\]是逃脱的]
\\\\ is an escaped \\ \\\\是逃脱的\\
\\s is any white space \\s是任何空白区域
@ is @ @@
\\" is an escaped " \\"是逃脱的"

"what does the + mean" “+意味着什么”

+ means "one or more" of what precedes the + +表示+之前的“一个或多个”

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

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