[Solved] Regular expression for phone numbers


If the first part of an alternation matches, then the regex engine doesn’t even try the second part.

Presuming you want to match only three-digit, 11 digit, or 11 digit hyphen 1 digit numbers, then you can use lookarounds to ensure that the preceding and following characters aren’t digits.

(?<!\d)(\d{3}|\d{11}|\d{11}-\d{1})(?!\d)

2

solved Regular expression for phone numbers