Hello Programmers, In this post, you will know how to solve the Incorrect Regex in Python HackerRank Solution. This problem is a part of the HackerRank Python Programming Series.
One more thing to add, don’t directly look for the solutions, first try to solve the problems of Hackerrank by yourself. If you find any difficulty after trying several times, then you can look for solutions.
Incorrect Regex in Python Hacker Rank Solution
problem
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.
Constraints :
- 0 < T < 100
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 in Python HackerRank Solutions
import re; N = int(input()) for _ in range(N): try: re.compile(input()) Output = True except re.error: Output = False print(Output)
Disclaimer: The above Problem (Incorrect Regex in Python) is generated by Hackerrank but the Solution is Provided by BrokenProgrammers. This tutorial is only for Educational and Learning purposes.
Next: Classes Dealing with Complex Numbers in python HackerRank Solution