From 37d21c5f43c3f02de998600781c43aa7a76a302e Mon Sep 17 00:00:00 2001 From: Maxim Slipenko Date: Mon, 16 May 2022 15:14:20 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D1=8F?= =?UTF-8?q?=D0=B5=D1=82=20=D0=B0=D0=BB=D0=B3=D0=BE=D1=80=D0=B8=D1=82=D0=BC?= =?UTF-8?q?=20=D0=B8=D0=B7=D0=B2=D0=BB=D0=B5=D1=87=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=B0=D0=B4=D1=80=D0=B5=D1=81=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AwesomeEmailExtractor.csproj | 1 + ExtactEmailsAlgorithm.cs | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 ExtactEmailsAlgorithm.cs diff --git a/AwesomeEmailExtractor.csproj b/AwesomeEmailExtractor.csproj index c86a1a0..3ae428d 100644 --- a/AwesomeEmailExtractor.csproj +++ b/AwesomeEmailExtractor.csproj @@ -46,6 +46,7 @@ + Form diff --git a/ExtactEmailsAlgorithm.cs b/ExtactEmailsAlgorithm.cs new file mode 100644 index 0000000..4509198 --- /dev/null +++ b/ExtactEmailsAlgorithm.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Text.RegularExpressions; + +namespace AwesomeEmailExtractor +{ + internal class ExtactEmailsAlgorithm + { + public static int Extract(string inputText, out List uniqueEmails) + { + // Регулярное выражение для поиска почтовых адресов + string pattern = @"\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b"; + + // Находим каждый почтовый адрес в тексте + var matches = Regex.Matches(inputText, pattern, RegexOptions.IgnoreCase); + + // Получаем количество найденных адресов + int countMatches = matches.Count; + + // Получаем уникальные почтовые адреса + uniqueEmails = matches.Cast().Select(m => m.Value).Distinct().ToList(); + + return countMatches; + } + } +}