Sort by

recency

|

302 Discussions

|

  • + 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")
    
  • + 0 comments

    This seems like a problem related to validating regular expressions. To solve this, you can use Python's re module, which provides the re.compile() method that can test whether a string is a valid regex pattern or not. Lucky7 exchange