Last matching symbol in Regex
Posted
by Menda
on Stack Overflow
See other posts from Stack Overflow
or by Menda
Published on 2010-03-12T17:57:55Z
Indexed on
2010/03/12
18:07 UTC
Read the original article
Hit count: 408
I couldn't find a more descriptive title, but here there is an example:
import re
m = re.search(r"\((?P<remixer>.+) (Remix)\)", "Title (Menda Remix)")
m.group("remixer") # returns 'Menda' OK
m = re.search(r"\((?P<remixer>.+) (Remix)\)", "Title (Blabla) (Menda Remix)")
m.group("remixer") # returns 'Blabla) (Menda' FAIL
This regex finds the first parenthesis, and I would like to match the last parenthesis for always getting 'Menda'. I've made a workaround to this using extra functions, but I would like a cleaner and a more consistent way using the same regex.
Thanks a lot guys.
© Stack Overflow or respective owner