Could use some help with a regex pattern

I’m having a hard time understanding what the following pattern is being used for:

#^\\[?[0-9\\.]+\\]?$#

From what I gather, the preg_match this came from seeks to find a possible IP address within an e-mail address. Personally, I’ve never seen or heard of an e-mail address with an IP in it, but I guess according to the RFC on the topic, it’s something that should be looked-out for?

Could someone help me understand what this is trying to find?

Yes, you can use IP addresses for the domain part of the e-mail address. It is allowed, but is uncommon. That regular expression intends to look for a match to an IP optionally surrounded by brackets . However, it allows for “32548468745.213477756.1233.1…343…]”, which is clearly NOT an IP address. Plus it also doesn’t allow for IPv6 addresses. Broken regex.

Using regular expressions for e-mail validation is a bad idea:

A breakdown of sorts for #^\[?[0-9\.]+\]?$#

^ - start of input

\[ - escaped [
? - non greedy 0 or 1 times

[…] a character set
[0-9\.] - a digit or a fullstop. (The fullstop doesn’t need escaping in a character set so [0-9.] should do the trick)

    • 1 or more times

\]? - ] 0 or 1 times

$ - end of input