Input Format
The first line contains integer , the number of test cases.
The next lines contains the string .
The next lines contains the string .
Constraints
Output Format
Print "True" or "False" for each test case without quotes.
Sample Input
2
.*\+
.*+
Sample Output
True
False
Explanation
.*\+ : Valid regex.
.*+: Has the error
.*+: Has the error
multiple repeat
. Hence, it is invalid.
Incorrect Regex - Hacker Rank Solution
import re for i in range(int(raw_input())): try: s = raw_input() re.compile(s) except: print False continue print True
My code. It works well for some test cases, needs modification though.
ReplyDeleteimport re
n = int(input())
for i in range(n):
text = input()
x = ".*\+"
#re.compile(text)
if x == text:
print(True)
continue
else:
print(False)
i = i+1
import re
ReplyDeletefor i in range(int(input())):
try:
s=input()
re.compile(s)
print(True)
except:
print(False)
not working bor-----
Delete