python re.search (regex) to search words who have pattern like {{world}} only -
i have on html file in have inserted custom tags {{name}}, {{surname}}. want search tags match pattern {{world}} not {world}}, {{world}, {world}, { word }, {{ world }}, etc. wrote small code
re.findall(r'\{(\w.+?)\}', html_string) it returns words follow pattern {{world}} ,{world},{world}} don't want. want match {{world}}. can please guide me?
um, shouldn't regex be:
'\{\{(\w.+?)\}\}' ok, after comments, understand requirements more:
'\{\{\w+?\}\}' should work you.
basically, want {{any nnumber of word characters including underscore}}. don't need lazy match in case may remove th ? in expression.
something {{keyword1}} other stuff {{keyword2}} not match whole now.
to keyword without getting {{}} use below:
'(?<=\{\{)\w+?(?=\}\})'
Comments
Post a Comment