Monday, 15 September 2014

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


What would be a function based on regexes f , in which an input text and string were given, Returns all the words with this string in the text. For example:

  f ("This is a simple lesson to test some basic things", "SI")  

will return:

  ["simple", "original"]  

(because these two words have substrings "si" ) < / P>

How to do this?

I'm not sure there is no better way to do this from my point of view, but something like that :

import again DF F (S, PT): Pat = R '(\ w *% s \ w *)'% pAT # Not thrilled < P> Works:

About this line refund, re.findall (pat, s) print f ("This is just a simple text to test some basic things"
  ['simple ',' Parent ']  

No comments:

Post a Comment