regex - Python regexes: return a list of words containing a given substring -


what function f based on regexes that, given input text , string, returns words containing string in text. example:

f("this simple text test basic things", "si") 

would return:

["simple", "basic"] 

(because these 2 words contain substring "si")

how that?

i'm not convinced there isn't better way approach, like:

import re  def f(s, pat):     pat = r'(\w*%s\w*)' % pat       # not thrilled line     return re.findall(pat, s)   print f("this simple text test basic things", "si") 

works:

['simple', 'basic'] 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -