Python regular expression to search for words in a sentence

后端 未结 3 1359
遥遥无期
遥遥无期 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

    question = "the total number of staff in 30?"
    find=["total","staff"]
    words=re.findall("\w+",question)
    result=[x for x in find if x in words]
    result
    ['total', 'staff']
    

提交回复
热议问题