PDA

View Full Version : Pattern Matching Help


IceManJoe
12-01-2002, 01:38 PM
Hi,

I would like to do an if statement if a string held in a variable is not like "Help" i.e, capital first letter and then lowercase. So that it catches all errors - e.g numbers. I would then like it to print to a text file that is open - named ErrorText.

I would also like to do the same as above if a number held in a varibale is not betwenn 0-100 so that it catches errors, e.g a letter.

All help would be super.

Joe

hrsdh
12-30-2002, 01:44 AM
Hi,

You could try the following:

--- For the one which requires an uppercase initial character, followed by a string of undetermined length of lowercase chars, test against the following condition:

if ($input_string=~/^([A-Z])([a-z]+)$/) {
#it matches;
} else {
#it doesn't;
}

(That will require one or more lowercase letters after the initial capital - if you want to make it zero or more, change the regex to $input_string=~/^([A-Z])([a-z]*)$/)

--- For the numerical test, try the following condition:

if (($number>=0) && ($number<=100)) {
} else {
}

Hope this helps :)
S.H.