how to check if string matches regex python 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