regular expression question
| From: | Matthew Lasar | Date: | Fri, 31 Aug 2007 18:27:25 +0000 |
| Subject: | regular expression question | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-261565@lists.php.net to get a copy of this message | ||
Hello:
I've adapted this regular expression script from a book, but I'm not clear why it works.
$email = "john.smith@email.alaska.com";
$pattern = "/[^@^\s]+@([-a-z0-9]+\.)+[a-z]{2,}/";
_______
if ( preg_match($pattern,$email) )
{
print "yes! " . $email . " matches!";
}
else { print "no match"; }
_______
When I run this script, I get the "yes! john.smith@email.alaska.com matches!" statement.
But I don't understand why the second half of the regular expression works. I'm talking about this part:
@([-a-z0-9]+\.)+[a-z]{2,}/";
why is it able to detect repeated sections of the email address after "@" that are separated by periods? like "@email.alaska.com" . It looks to me like it's only looking for one example of that pattern. Does the "()" allow an unlimited number of patterns to pass?
thanks for any and all guidance
Matthew
Matthew Lasar || llfcc.net