304 North Cardinal St.
Dorchester Center, MA 02124

# Incorrect Regex Hacker Rank Solution – Queslers

## Problem: Incorrect Regex Hacker Rank Solution

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.

• 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 Hacker Rank Solution in python 2

``````import re

for t in xrange(int(input())):
S = raw_input()
try:
re.compile(S)
print True
except:
print False
``````

### Incorrect Regex Hacker Rank Solution in python 3

``````# Enter your code here. Read input from STDIN. Print output to STDOUT
import re
for _ in range(int(input())):
ans = True
try:
reg = re.compile(input())
except re.error:
ans = False
print(ans)
``````

### Incorrect Regex Hacker Rank Solution in pypy

``````# Enter your code here. Read input from STDIN. Print output to STDOUT
import re
for _ in xrange(input()):
try:
print bool(re.compile(raw_input()))
except:
print 'False'
``````

### Incorrect Regex Hacker Rank Solution in pypy 3

``````import re
T = int(input())
for _ in range(T):
try:
re.compile(input())
print(True)
except Exception:
print(False)
``````
##### Incorrect Regex Hacker Rank Solution Review:

In our experience, we suggest you solve this Incorrect Regex Hacker Rank Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

Incorrect Regex problem is available on Hacker Rank for Free, if you are stuck anywhere between a compilation, just visit Queslers to get Incorrect Regex Hacker Rank Solution

##### Conclusion:

I hope this Incorrect Regex Hacker Rank Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Hacker Rank, Leetcode, Codechef, Codeforce Solution.

This Problem is intended for audiences of all experiences who are interested in learning Programming in a business context; there are no prerequisites.

Keep Learning!

More Hacker Rank Problem & Solutions >>

Staircase Hacker Rank Solution

A Very Big Sum Hacker Rank Solution

Diagonal Difference Hacker Rank Solution

Nested Lists Hacker Rank Solution

Lists Hacker Rank Solution