This will work for numbers in the US:
^ # beginning of string, or BOL in multi-line mode
(?:[+]?1[-. ]){0,1} # optional calling code, not captured
\(? # optional common prefix for area code, not captured
([2-9][0-8][0-9])? # optional NANP-allowed area codes, captured in $1
[)-. ]* # optional common delimiters after area code, not captured
( # begin capture group $2 for exchange code
[2-9] # first digit cannot be a 1
(?:[02-9][0-9]|1[02-9])) # second and third digit cannot be "11"
) # end capture group for exchange
[-. ]? # common delimiters between exchange and SN, not captured
([0-9]{4}) # subscriber number, captured in $3
(?: # start non-capturing group for optional extension
\s*(?:x|ext|ext.)\s* # common prefixes before extension numbers
(\d+) # optional extension, captured in $4
){0,1} # end non-capturing group
$ # end of string, or EOL in multi-line mode
This handles calling codes (optional), semi-validated area codes (optional) and exchange codes, extension numbers (optional), and captures each portion of the phone number in a separate variable for easy extraction and manipulation.
Using this expression in .NET, you would need to include the IgnorePatternWhitespace and MultiLine flags so commas are ignored and the ^
and $
characters find phone numbers on any line in the string.