I have on HTML file in which I have inserted the custom tags like {{name}}, {{surname}}. Now I want to search the tags who exactly match the pattern like {{world}} only not even {world}}, {{world}, {world}, { word }, {{ world }}, etc.
I wrote the small code for the
re.findall(r'\{(\w.+?)\}', html_string)
It returns the words which follow the pattern {{world}} ,{world},{world}}
that I don’t want. I want to match exactly the {{world}}. Can anybody please guide me?
Um, shouldn’t the regex be:
Ok, after the comments, I understand your requirements more:
should work for you.
Basically, you want {{any nnumber of word characters including underscore}}. You don’t even need the lazy match in this case actually so you may remove th
?in the expression.Something like
{{keyword1}} other stuff {{keyword2}}will not match as a whole now.To get only the keyword without getting the {{}} use below: