how to check if a python string matches a pattern code example
Example: check if valid regex string python
import re
string = '['
try:
re.compile(string)
is_valid = True
except re.error:
is_valid = False
import re
string = '['
try:
re.compile(string)
is_valid = True
except re.error:
is_valid = False