Python regular expression to search for words in a sentence

后端 未结 3 1352
遥遥无期
遥遥无期 2021-01-07 08:25

Im still learning the ropes with Python ad regular expressions and I need some help please! I am in need of a regular expression that can search a sentence for specific word

3条回答
  •  粉色の甜心
    2021-01-07 09:00

    Have you though to use something beyond Regex?

    Consider this and and if it works expand from this solution

    >>> 'total' in question.split()
    True
    

    Similarly

    >>> words = {'total','staff'}
    >>> [e   for e in words if e in question.split()]
    ['total', 'staff']
    

提交回复
热议问题