Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

perl quantifier prob 1

Status
Not open for further replies.

rickict

IS-IT--Management
Apr 29, 2005
18
GB
im learning about regular expressions and quantifing and im doing an exercise to validate an email address.
i can't seem to quantifie an exact amount of letters using
[a-z]{3} to say exactly three letters.
the script below just doesn't seem to see the email as FALSE and prints the TRUE response instead.
i just can't see what im doing wrong??

$email ='rick@popex.comm'; # com has 4 letters not 3.
if ($email =~ m/[a-z]+@[a-z]+\.[a-z]{3}/)
{
print "yeah\n";
print $email;
}
else
{
print.......

any help would be great..........rick
 
Regular expressions will complete as return a positive status as soon as possible.
The regex you supplied finishes matching before the last 'm' but because it has succeeded to match every character in the regex, it completes as successful.
To tell it that you DON'T want the last 'm' you must tell it that there must be nothing after the 3rd char.
To do this you could change your regex to 'm/[a-z]+@[a-z]+\.[a-z]{3}$/'

Trojan
 
great, thanks very much trojanwarblade.......rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top