Two notes: it would be better to use raw strings (r"string") and to maybe do r"\(a|b|c|d)" instead of r"(\a|\b|\c|\d)" (use distributivity, in other words). So, I think you want this: def_re = re.compile(r"\(newcommandx|renewcommandx|global\long\def)(\[a-zA-Z]+)(.+)") Regards, Neven Sajko