Python extract sentence containing word

后端 未结 6 1725
孤独总比滥情好
孤独总比滥情好 2020-12-09 10:52

I am trying to extract all the sentence containing a specified word from a text.

txt=\"I like to eat apple. Me too. Let\'s go buy some apples.\"
txt = \".\"         


        
6条回答
  •  孤街浪徒
    2020-12-09 11:41

    In [3]: re.findall(r"([^.]*?apple[^.]*\.)",txt)                                                                                                                             
    Out[4]: ['I like to eat apple.', " Let's go buy some apples."]
    

提交回复
热议问题