We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Incorrect Regex
Incorrect Regex
Sort by
recency
|
330 Discussions
|
Please Login in order to post a comment
is not working. Also tried the following import re
pattern = r".*+"
try: re.compile(pattern)
except re.error: print("Non valid regex pattern") exit() Please suggest what is the correct solution, else is there some thing with the validator in hackerrank ?
Please except re.error: print("Non valid regex pattern") exit()
`In Python 2
import re
num_test_cases = int(raw_input())
for _ in range(num_test_cases): regex = raw_input() try: re.compile(regex) print(True) except re.error: print(False)
`
This works with PyPy3. Thank you codersaad for the idea. This is the same code but without a function.
import re
n = int(input())
for _ in range(n): regex = input().strip() try: if re.search(r'(*|+|\?){2,}', regex): print("False") else: re.compile(regex) print("True") except re.error: print("False")
This works with PyPy3. Thank you codersaad for the idea. This is the same code but without a function.
import re
n = int(input())
for _ in range(n): regex = input().strip() try: if re.search(r'(*|+|\?){2,}', regex): print("False") else: re.compile(regex) print("True") except re.error: print("False")
my solution: import re for i in range(int(input())): try: re.compile(input()) print(True) except re.error: print(False) but it is giving output as TRUE TRUE and hence failing the sample test case. Although i did solve it using python 2 can anyone help me with a pypy3 solution