HackerRank Python - Incorrect Regex

You are given a string S.
Your task is to find out whether S is a valid regex or not.

  1. # Enter your code here. Read input from STDIN. Print output to STDOUT
  2. import re
  3. for _ in range(int(input())):
  4. try:
  5. print(bool(re.compile(input())))
  6. except:
  7. print('False')

download android app