How to Check if a Word Exists in a Text Using Python

When working with text data, you often need to check whether a specific word appears in a given text. The Python function below provides a simple way to do this using regular expressions: import re def word_in_text(word, text): word = word.lower() text = text.lower() match = re.search(word, text) if match: return True return False

Mar 22, 2025 - 17:25
 0
How to Check if a Word Exists in a Text Using Python

When working with text data, you often need to check whether a specific word appears in a given text. The Python function below provides a simple way to do this using regular expressions:

import re

def word_in_text(word, text):
    word = word.lower()
    text = text.lower()
    match = re.search(word, text)

    if match:
        return True
    return False