Incorrect Regex Python Hackerrank Solution

0

You are given a string S.

Your task is to find out whether S is a valid regex or not.

Input Format

The first line contains integer T, the number of test cases.

The next T lines contains the string S.

Output Format

Print "True" or "False" for each test case without quotes.

Sample Input 


    2
    . *\+
    . *+

Sample Output


    True
    False

Explanation

.*\+ : Valid regex.

.*+: Has the error multiple repeat. Hence, it is invalid.

Incorrect Regex Python Hackerrank Solution 


    import re

    for _ in range(int(input())):
            try:
                    print(bool(re.compile(input())))
            except:
                       print('False')

Happy Learning by shouterfolk

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.
Post a Comment (0)
Our website uses cookies to enhance your experience. Learn More
Accept !