I have the following perl regex pattern to find an e-mail address within a string (a one line string):
preg_match('/[^\s()\[\]{}@,.]{1}[^\s()\[\]{}@,]*@[^\s()\[\]{}@,.]{1}[^\s()\[\]{}@,]*[.]{1}[a-z]{2,4}/i', $string, $array)
I'm not sure about the e-mail address standards, but I suspect that the following characters are not allowed: COLOR=red{}[],[/COLOR] and that an address can't start with a period, or have a period immediately following the '@' symbol. Also the domain extension must be 2-4 characters long.
My question is: have I written this properly according to the few rules I have mentioned? It appears to work, but I'm not sure if I have missed something which would break these rules. Here is the pattern broken down into many lines with the logic I am trying to create next to it in blue:
[COLOR=red][^\s()\[\]{}@,.]{1}[/COLOR] [COLOR=blue]the first character can't be a space or one of these ()[]{}@,.[/COLOR]
[COLOR=red][^\s()\[\]{}@,]*[/COLOR] [COLOR=blue]the part of the string up to the '@' must be anything but a space or one of these ()[]{}@,[/COLOR]
[COLOR=red]@[/COLOR] [COLOR=blue]there has to be a single '@' symbol[/COLOR]
[COLOR=red][^\s()\[\]{}@,.]{1}[/COLOR] [COLOR=blue]the very next character can't be a space or one of these ()[]{}@,.[/COLOR]
[COLOR=red][^\s()\[\]{}@,]*[/COLOR] [COLOR=blue]the part of the string up to the last '.' must be anything but a space or one of these ()[]{}@,[/COLOR]
[COLOR=red][.]{1}[/COLOR] [COLOR=blue]there must be at least exactly 1 ocurrance of a '.' before the ending domain...[/COLOR]
[COLOR=red][a-z]{2,4}[/COLOR] [COLOR=blue]the domain must be alphanumeric and only 2-4 characters long[/COLOR]
Any thoughts?