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