how to reverse a regex in python?
python, regex, reverse
Solution
A good way is (which will be faster than using a `lambda` in the sorted):
sorted(re.finditer(...,text),key=attrgetter('group'),reverse=True):
Or you could turn the iterator into a list and reverse it:
for i in reversed(list(re.finditer('id (.+?) result (.+)', text))):
Problem
My regex is something like below ``` text = 'id 5 result pass id 4 result fail id 3 result fail id 2 result fail id 1 result pass' for i in re.finditer('id (.+?) result (.+)', text): id = i.group(1) result = i.group(2) print 'id' print 'result' ``` The output is OK. But how do I reverse it to get the results in the other order where id will start from 1 with the pass or fail result