I'm trying to write a regular expression in perl to pull student usernames from input. Our campus usernames consist of the first five letters of our last name, followed by first initial, followed by middle initial (x if the person doesn't have one), followed a number representing the year they started. This number used to be single digit, but new ones are now 2. So as an example, my username is fitzpjm3.
Some things to consider here:
- some last names don't have more than 5 letters, so usernames will vary in length
- there is an optional 0 at the end of the username (like in robbiet04)
The expression I have been building on looks like
Code:
m/^([a-z]*0?[0-9])$/
This searches, from beginning of string to end, for any number of letters, followed by a digit that may or may not have a leading 0. The only trouble I am having is that this matches pure digits. So I get a positive return on a username, but a digit will come back as true as well. How do I get it to only match when everything is true?