Incorrect Regex Hackerrank Python Solution
You are given a string S.
Your task is to find out whether S is a valid regex or not.
The first line contains integer T, the number of test cases.
The next T lines contains the string S.
Print “True” or “False” for each test case without quotes.
2 .*\+ .*+
.*\+ : Valid regex.
.*+: Has the error
multiple repeat. Hence, it is invalid.
#Incorrect Regex Hackerrank Python Solution import re for _ in range(int(input())): ans = True try: reg = re.compile(input()) except re.error: ans = False print(ans)
Disclaimer: This problem is originally created and published by HackerRank, we only provide solutions to this problem. Hence, doesn’t guarantee the truthfulness of the problem. This is only for information purposes.