Reputation: 17148
Could someone tell me what the regular expression would be to match:
number with n
digits where n
would be provided or (
or )
Upvotes: 23
Views: 45462
Reputation: 354874
Simple:
\(|\)|\d{n}
replace n
with the number of digits you need. If you need to match a complete string, then put parentheses around the expression and prepend ^
and append $
.
Upvotes: 28
Reputation: 138
I believe this will work for you. It matches strings with n numbers or strings like "(" or ")". Exmpl.: for n = 2 it matches strings like "12", "22" ....
^([0-9]{n})$|^([()]{1})$
Upvotes: 1