Home: Perl Programming Help: Regular Expressions:
how 2 distinquish.



v0dka
Novice

Oct 1, 2002, 7:46 AM


Views: 9601
how 2 distinquish.

regular Expessions validation. Edit | Delete | Quote | Reply | Private Reply
I need to be a bit of a cheeky badger!

My program will take 2 types of user names. These will be in the format of 2 letters and 2 digits e.g zx12, OR 2 letters and 3 digits eg. as123. I need my program to distinguish between the 2.

if ($username =~ 2 letters and 2 digits) {

do this

}else if ($username =~ 2 letters and 3 digits) {

do this

}

Any help will be much appreciated cheers!!



Paul
Enthusiast

Oct 1, 2002, 8:41 AM


Views: 9600
Re: [v0dka] how 2 distinquish.


Code
if ($username =~ /^[a-z]{2}\d{2,3}$/i) {



uri
Thaumaturge

Oct 1, 2002, 11:19 PM


Views: 9595
Re: [RedRum] how 2 distinquish.


In Reply To

Code
if ($username =~ /^[a-z]{2}\d{2,3}$/i) {



that doesn't do what the OP asked. it matches either name format but he wanted to distinguish between a 2 or 3 digit ending part. that should be an easy change for you to make so i won't do it myself.

uri


Bode
Novice

Oct 2, 2002, 3:33 AM


Views: 9592
Re: [v0dka] how 2 distinquish.

Wink Cheers people!