My regex is not working properly. I\'m showing you before regex text
and after regex text
. I\'m using this regex re.search(r\'(?ms).*?{{(Infobox
Your regex is catching everything between the first {{
and the first }}
, which is in the "country" entry of the infobox. If you want everything between the first {{
and the last }}
, then you want to make the .*
inside the braces greedy by removing the ?
:
re.search(r'(?ms).*?{{(Infobox film.*)}}', text)
Note that this will find the last }}
in the input (eg. if there's another template far below the end of the infobox, it will find the end of that), so this may not be what you want. When you have nesting things like this, regex is not always the best way to search.