check if substring in string python regex 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