in reply to E-mail Regular Expression
The above replies offer good advice as to how to check an obtained e-mail address is valid, but I believe the question was about a regular expression which could pull an e-mail address from a string of text (which you would then, of course, feed to validating code).
I had to do this once at work and knocked up a quick regexp for an e-mail address. I think it's extremely messy, but it seemed to work in all test cases and also in production. (I think it's messy because I made sure words started and ended with only a letter or number, but the middle of words could contain things such as dashes, underscores, single quotes, or what ever was applicable.)
I used: $string =~ /([A-Z0-9]+[A-Z_.'0-9-]*[A-Z0-9]{1}\@{1}(?:[A-Z0-9]+[A-Z0-9-]*[A-Z0-9]{1}\.)+[A-Z0-9]+[A-Z0-9-]*[A-Z0-9]{1})/i; to place the e-mail address in $1.
|
---|