• + 0 comments

    python 3 solution

    python added support for possesive quantifiers (*+,++,?+,{ }+) from python 3.11, but the expected outputs are not updated to align with the updated python version. so we need to handle possesive quantifiers separately.

    import re
    res="False"
    pattern = r'(?:[*+?]|\{\d+(?:,\d*)?\})\+'    # ++,*+,?+,{..}+
    for _ in range(int(input())):
        inp=input()
        if re.findall(pattern,inp):
            res="False"
        else:
            try:
                re.compile(inp)
                res="True"
            except re.error as e:
                res="False"
        
        print(res)