I am not understanding why this regex pattern is not matching as expected. I am testing this pattern on https://regexr.com.
regex =/^1?\((?=\d{3}\))[-. ]?(\d{3})$/
sample = 1(123) 123
My understanding is first pattern should be number 1 or nothing then 3 digits in closed parentheses or no parentheses at all. There should not be open parentheses which will be the case when we only use (?(\d{3})\)?
and after [-. ]
which is optional, followed by 3 digits end.