Find last match with python regular expression

Posted by SDD on Stack Overflow See other posts from Stack Overflow or by SDD
Published on 2010-05-10T11:20:12Z Indexed on 2010/05/10 11:24 UTC
Read the original article Hit count: 265

Filed under:
|

I wanto to match the last occurence of a simple pattern in a string, e.g.

list = re.findall(r"\w+ AAAA \w+", "foo bar AAAA foo2 AAAA bar2)
print "last match: ", list[len(list)-1]

however, if the string is very long, a huge list of matches is generated. Is there a more direct way to match the second occurence of "AAAA" or should I use this workaround?

© Stack Overflow or respective owner

Related posts about python

Related posts about regex