regular expression question
Hello:
I've adapted this regular expression script from a book, but I'm not
clear why it works.
$email = "john.smith@xxxxxxxxxxxxxxxx";
$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@xxxxxxxxxxxxxxxx
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
.
Relevant Pages
- Re: RegEx: How to ignore the number of whitespaces?
... a "simpler" regular expression syntax is likely to bite you eventually, ... but that some of these character sequences may be "marked" as ... This is a regular expression "if" conditional statement, ... do not understand why the pattern "personal computer" will only match ... (microsoft.public.dotnet.framework) - Re: Expert script (.bat) writers help needed (strip double-quote from string)
... Sets or returns the regular expression pattern being searched for. ... Always a RegExp object variable. ... May include any of the regular expression characters defined in the table in the Settings section. ... (microsoft.public.windowsxp.help_and_support) - FAQ 6.23 How do I match a regular expression thats in a variable?
... How do I match a regular expression that's in a variable? ... We don't have to hard-code patterns into the match operator (or anything ... have the pattern in $regex, you use that variable in the match operator. ... and the pattern still has to be valid or Perl will complain. ... (comp.lang.perl.misc) - FAQ 6.23 How do I match a regular expression thats in a variable?
... How do I match a regular expression that's in a variable? ... We don't have to hard-code patterns into the match operator (or anything ... have the pattern in $regex, you use that variable in the match operator. ... and the pattern still has to be valid or Perl will complain. ... (comp.lang.perl.misc) - FAQ 6.23 How do I match a regular expression thats in a variable?
... How do I match a regular expression that's in a variable? ... We don't have to hard-code patterns into the match operator (or anything ... have the pattern in $regex, you use that variable in the match operator. ... and the pattern still has to be valid or Perl will complain. ... (comp.lang.perl.misc) |
|