# -*- coding: iso-8859-1 -*- import re re_exc_line = re.compile ( # ignore everything before the first match r'^.*' + # first group (includes second | third) r'(?:' + # second group "(line) (file)" r'(?:' + # (text to ignore, line [number]) r'\([^,]+\s*,\s*line\s+(?P\d+)\)' + # any text ([filename]) any text r'.*\((?:(?P[^)]+))*\).*' + # end of second group r')' + # or r'|' + # third group "(file) (line)" r'(?:' + # ([filename]) r'\((?:(?P[^)]+))*\)' + # any text (text to ignore, line [number]) any text r'.*\([^,]+\s*,\s*line\s+(?P\d+)\).*' + # end of third group r')' + # end of first group r')' + # any text after it r'.*$' , re.I ) msg = ( r"Error: Error during parsing: invalid syntax " + r"(D:\Projects\retest\ver_700\lib\_test\test_sapekl.py, line 14) " + r"-- Error during parsing: invalid syntax " + r"(D:\projects\retest\ver_700\modules\sapekl\__init__.py, line 21) " + r"-- Attempted relative import in non-package, or beyond toplevel " + r"package" ) m = re_exc_line.match(msg) if m: print m.groupdict() else: print "No match!"