How to write regex that matches non digit elements in string, but with exception of "(" and ")"?

How to write regex that matches non digit elements in string, but with exception of "(" and ")"?
0

#1

I need it for this chlg: https://www.freecodecamp.com/challenges/validate-us-telephone-numbers
I need to check first does it contains any other character that is not digit, with exception of “(” , “)” .
And then to check other thing like validating number…


#2

var regex = /[\D()]/g


#3

Can u take look at this regex
(\d\d\d) \d\d\d-\d\d\d\d

I need to search for it in
1 (555) 555-5555

but no success, but when i put this like
(\d\d\d)\S \d\d\d-\d\d\d\d

It finds. I expect when i put in regex whitespace (" "), that it literaly search for, am i wrong? Why we need to set this \S thing?


#4

@nameToReachPeople try \(\d\d\d\) \d\d\d-\d\d\d\d

notice two extra “”

using only (\d\d\d) creates something called a Capturing group.