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