LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Perl: Check if "$str" is of type [A-Z]<char string>[0-9][0-9] (http://www.linuxquestions.org/questions/programming-9/perl-check-if-%24str-is-of-type-%5Ba-z%5D-char-string-%5B0-9%5D%5B0-9%5D-450921/)

introuble 06-02-2006 10:07 AM

Perl: Check if "$str" is of type [A-Z]<char string>[0-9][0-9]
 
Hello !

In a Perl script, I have a string, $str. I need to check if the string is of the form: [A-Z]<string consisting of chars a-z>[0-9][0-9] and print "yes" if it is, "no" if it isn't.

Matching examples: Awhatever49, Xwhenever30, Paaaa00, Thisisnice73.

Can anyone help me with this ?

druuna 06-02-2006 10:24 AM

Hi,

Something like this should work:
Code:

#!/usr/bin/perl

#$str = "Awhatever49";
$str = "W49";

if ( $str =~ /[A-Z][a-z][a-z]*[0-9][0-9]/) {
  print "Yes.\n"
} else {
  print "No.\n"
}

Hope this helps.

introuble 06-02-2006 10:33 AM

Danke schon


All times are GMT -5. The time now is 01:17 AM.