Sort by

recency

|

303 Discussions

|

  • + 0 comments
    import re
    
    n = int(input())
    for i in range(0,n):
        try:
            a = (re.compile(input()))
            print(bool(a))
        except re.error:
            print('False') 
    
  • + 0 comments
    #In Python 3, it will not work; but it will work in Pypy 3
    import re 
    T =int(input())
    for x in range(T):
        S = input()
        try:
            if re.compile(S):
                print("True")
        except:
            print("False")
    
  • + 0 comments

    This is my code for this problem , i used Pypy 3 instead of Python 3. Below is my code

    import sys
    import re
    
    lista = []
    for line in sys.stdin:
        if(line != ''):
            lista.append(line.rstrip())
    
    for i in range(int(lista[0])):
        try:
            re.compile(lista[i+1])
            is_valid = True
            print('True')
        except re.error:
            is_valid = False
            print('False')
    
  • + 0 comments
    # works in Pypy 3 but not in Python3
    import re
    
    n = int(input())
    
    for x in range(n):
        s = input()
        try:
            re.compile(s)
            print("True")
        except re.error:
            print("False")
    
  • + 0 comments

    Use pypy3

    import re
    def check_reg(p):
        try:
            re.compile(p).match("")
            print("True")
        except:
            print("False")