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

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -