Sort by

recency

|

320 Discussions

|

  • + 0 comments

    Try Like this

    import re

    T = int(input()) invalid_repeats = ['++', '**', '??', '+', '+', '?', '?', '+?', '??']

    for _ in range(T): S = input().strip()

    # Basic invalid pattern check
    is_invalid = any(rep in S for rep in invalid_repeats)
    
    if is_invalid:
        print("False")
        continue
    
    try:
        re.compile(S)
        print("True")
    except re.error:
        print("False")
    
  • + 0 comments

    how to solve this code

  • + 0 comments

    Accepted solution for python 2

    import re
    for _ in range(int(raw_input())):
        try:
            re.compile(raw_input().strip())
            print(True)
        except re.error:
            print(False)
    
  • + 2 comments

    With Python3.11, both sample inputs return True.

  • + 0 comments

    Here is HackerRank incorrect Regext in python solution - https://programmingoneonone.com/hackerrank-incorrect-regex-solution-in-python.html