import re
regex = r"^0(a|b)*1$" # an example
if re.match(regex, "0abaab1"):
print "yes"
^ string begin
$ string end
A,a,1,… match themselves
. any single char
x* 0,1,2 of x
x? 0,1 of x
() grouping
x{m} exactly m x's
x{m,n} m to n x's
[abc] one char from set
x|y x or y