re.findall(r'\{(.+?)\}', request.params['upsell'])
This will return a list in which each entry represents the contents of another group of curly braces. Note that this will not work for nested braces.
?
after .+
will make him lazy (as opposed to greedy). This means that the match will stop at the first "}", instead of continuing to match as many characters as possible and ending with the last closing bracket.
re.findall()
will search your string and find all matching matches and return the group. Alternatively, you can use re.finditer()
, which will re.finditer()
over Match objects, but then you will need to use match.group(1)
to get only what is inside the curly braces. This is also what you will need to change in your example, match.group()
returns a complete match, not a captured group, for this you need to put the number for the group you need.
source share