how to check if string is present in python regex code example
Example 1: check if valid regex string python
import re
string = '['
try:
re.compile(string)
is_valid = True
except re.error:
is_valid = False
Example 2: check if string contains python
>>> str = "Messi is the best soccer player"
>>> "soccer" in str
True
>>> "football" in str
False