Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 610
Sushanth -- Avatar asked Dec 09 '22 15:12

Sushanth --


1 Answers

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
    )
)$
like image 86
Kavi Siegel Avatar answered Dec 11 '22 10:12

Kavi Siegel