Regex para que coincida con todos los formatos de números de teléfono de nosotros
En primer lugar, diría que he visto muchos ejemplos aquí y en Google, pero ninguno encontró que coincida con todas las condiciones en las que busco algunos top 3 que no estén por debajo de algunos. Por favor, déjame saber cómo ponerlos a todos en un solo lugar.
(xxx)xxxxxxx
(xxx) xxxxxxx
(xxx)xxx-xxxx
(xxx) xxx-xxxx
xxxxxxxxxx
xxx-xxx-xxxxx
Utilizando como:
const string MatchPhonePattern =
@"\(?\d{3}\)?-? *\d{3}-? *-?\d{4}";
Regex rx = new Regex(MatchPhonePattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
// Find matches.
MatchCollection matches = rx.Matches(text);
// Report the number of matches found.
int noOfMatches = matches.Count;
// Report on each match.
foreach (Match match in matches)
{
tempPhoneNumbers= match.Value.ToString(); ;
}
SALIDA DE MUESTRA:
3087774825
(281)388-0388
(281)388-0300
(979) 778-0978
(281)934-2479
(281)934-2447
(979)826-3273
(979)826-3255
1334714149
(281)356-2530
(281)356-5264
(936)825-2081
(832)595-9500
(832)595-9501
281-342-2452
1334431660