views:

46

answers:

1

normally,we use regular expression match from left to right direction,i want to know is there some switch can match from the right to left in python? or in any other language has this feature embedded

e.g.

abcd1_abcd2

if give a abcd regular expression,it will match two abcd,what i want is put the last match at first in a reverse direction match

+1  A: 

You can reverse the list as proposed by @SilentGhost:

import re

for s in reversed(re.findall('abcd.', 'abcd1_abcd2')):
    print s
Sacha
in fact i need use finditer,but it was a yield expression,so i use [for match in finditer(obj)][::-] instead
mlzboy