Regular Expressions in Python

Jeff Epler jepler at unpythonic.net
Mon Mar 1 09:48:47 EST 2004


opt_spaces  = " *"
identifier  = "[A-Za-z_][A-Za-z0-9_]+"
comment     = "\*.*"
opt_comment = "(%s)?" % comment

pat = re.compile(opt_spaces + identifier + opt_spaces + opt_comment + "$")

for test in (
        "  END *This is a comment",
        "  END  e * This is a line with an error (e)"):
    print test, pat.match(test)

Jeff




More information about the Python-list mailing list