Regular expressions - match only specified string length

I'm learning regex. Here I'm checking a string of type aA1 but want also to check it is only 3 characters long. Is there a better way of doing it please?

str = raw_input("input in form 'aA1' please >")
check = re.compile("[a-z][A-Z][0-9]")
if len(str) == 3:
validate = check.match(str)
if validate:
print "Correct string"
else:
print "Incorrect string"
else:
print "Wrong length"

• (Of course there should be 'import re' at the top – j-o Oct 5 '14 at 10:55

Similarly, $matches right after the last character in the string. c$ matches c in abc, while a$does not match at all. With anchors you may skip length test entirely. So: import re str = raw_input("input in form 'aA1' please >") check = re.compile("^[a-z][A-Z][0-9]$")