using System using System Collections Generic using System Linq using

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
namespace RegExPhoneNumber
{
class FindPhoneNumber
{
static void Main(string[] args)
{
string data1 = System.IO.File.ReadAllText(@"..\..\..\TextFile1.txt", Encoding.Default);
string pattern = @"((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}";
Regex RegEx = new Regex(pattern);
MatchCollection matches = RegEx.Matches(data1);
if (matches.Count != 0)
{
Console.WriteLine("В тексте есть телефонные номера:");
foreach (Match m in matches)
{
Console.WriteLine(m.Value);
}
}else{
Console.WriteLine("В тексте нет телефонных номеров");
}
Console.ReadKey();
}
}
}