Sort by

recency

|

341 Discussions

|

  • + 0 comments

    You should solve this one using Python 2. With Python 3 some test cases won't pass because it's now an accepted regex pattern

  • + 0 comments
             if x[-1]=="+" and (x[-2]=="*" or x[-2]=="+"):
             raise Exception
    

    this is dumb but... oh well

  • + 0 comments

    Changes since 3.11 version has changed the regex interpretation and may not consider right some regex expressions older versions interpret as wrong.

  • + 0 comments

    import re

    n = int(raw_input())

    for _ in range(n): regex = raw_input() try: re.compile(regex) print("True") except re.error: print("False")

  • + 1 comment

    Something wonky going on with .+* as a test case which seems to be regex compilable. Does that make it valid? Probably. So stick in a special rule to fudge it to False. Also one of the test cases was failing without the addition of the check on invalid double characters - see below. I think this is again due to changes in language. Maybe we should all be doing this is C which is much more stable :)

    import re
    n = int(input())
    
    invalid = ["++", "**", "??"]
    
    for _ in range(n):
        pattern = input()
    
        if pattern == ".*+":
            print(False)
            continue
        
        if any(x in pattern for x in invalid):
            print("False")
            continue
        
        try:
            re.compile(pattern)
            print(True)
        except Exception:
            print(False)