make your life easy, use something like this:

$_ = 'foo@bar';
print "ILLEGAL!" if /[^a-zA-Z]/;


the ^ in side the character class says, everything NOT belonging to what's
in this class
it should be a bit faster then checking the entire string for sure.

hth,

Jos Boumans


----- Original Message -----
From: "Robert Lubej" <[EMAIL PROTECTED]>
To: "beginners perl" <[EMAIL PROTECTED]>
Sent: Monday, August 06, 2001 12:57 PM
Subject: Re: Checking for letters and spaces in regular expression??


> Carlos C.Gonzalez wrote:
>
> >Hi everyone,
> >
> >Given the following code why does it print out "Valid chars in string."?
> >In other words why does the space between "San" and "Jose" not make the
> >if expression true?
> >
> >my $string = "San Jose";
> >
> >if ($string !~ /[a-zA-Z]/) {
> >  print "Invalid characters in string."
> >}
> >else {
> >  print "Valid chars in string."
> >}
> >
> You are saying - "Report invalid characters unless there are
> alphabetical characters in the string".
> But there are alphabetical characters in the string...
> You shuld have said - "Report invalid characters unless there are ONLY
> alphabetical characters in the string, from the beginning to the and".
>
> That is instead of:
>
> if ($string !~ /[a-zA-Z]/) {
>
> you should have written
>
> if ($string !~ /\A[a-zA-Z]\Z/) {
>
> (\A meaning beginning and \Z the end of the string).
>
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to