check regex python 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: python regex tester

Find below are online regex tester

https://regex101.com/
https://pythex.org/
http://www.pyregex.com/
https://www.debuggex.com/
  
Here you insert your regular expression and get the test result.
Thank you !!!

Example 3: check if valid regex string python

import re
string = '['
try:
    re.compile(string)
    is_valid = True
except re.error:
    is_valid = False