Sort by

recency

|

330 Discussions

|

  • + 0 comments

    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()

  • + 0 comments

    `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)

    `

  • + 0 comments

    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")

  • + 0 comments

    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")

  • + 2 comments

    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