rendered paste bodyimport retable = {'comment': r'#[^\n]*','float_number': r'([0-9]+\.[0-9]*)|([0-9]*\.[0-9]+)','number': '[0-9]+','spaces': r'[ \t]+','newline': r'[\n\r]'}ordering = [['float_number', 'number']]def cmp_order(a, b): for set in ordering: if a in set and b in set: return cmp(set.index(a), set.index(b)) return cmp(a, b)def conv1(table, order=cmp): r = [] for k in sorted(table.keys(), cmp=order): r.append('(?P<%s>%s)' % (k, table[k])) exp = '|'.join(r) return exp, re.compile(exp)ccc = conv1(table, cmp_order)[1]src = '''1. 234 555.0123 # aaa bbb # paf# huhu.666# coin'''r2 = map(lambda x: (x.lastgroup, x.group()), ccc.finditer(src))