python regex check match code example
Example 1: check string equal with regular expression python
import re
pattern = re.compile("^([A-Z][0-9]+)+$")
pattern.match(string)
Example 2: check if valid regex string python
import re
string = '['
try:
re.compile(string)
is_valid = True
except re.error:
is_valid = False
Example 3: python regex match words
# credit to Stack Overflow user in source link
import re
re.search(r'\bis\b', your_string)