How do I check for an EXACT word in a string in python

后端 未结 7 2059
再見小時候
再見小時候 2020-12-01 18:27

Basically I need to find a way to figure out a way to find the EXACT word in a string. All the information i have read online has only given me how to search for letters in

7条回答
  •  时光取名叫无心
    2020-12-01 19:00

    Actually, you should look for 'This is correct' string surrounded by word boundaries.

    So

    import re
    
    if re.search(r'\bThis is correct\b', text):
        print('correct')
    

    should work for you.

提交回复
热议问题