Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Text.RegularExpressions;
- /* #18. Write a program for extracting all email addresses from given text. All substrings that match the format <identifier>@<host>…<domain> should be recognized as emails. */
- class ExtractEMailAddresses
- {
- static void Main()
- {
- Console.WriteLine("Please enter a text below:");
- string inputText = Console.ReadLine();
- string[] arrayOfExpressions = inputText.Split(' ');
- Console.WriteLine("The e-mail addresses are:");
- for (int i = 0; i < arrayOfExpressions.Length; i++)
- {
- if (Regex.IsMatch(arrayOfExpressions[i], @"[\w., \-]{2,20}@[\w., \-]{2,20}[.]{1}[\w.]{2,6}"))
- {
- // Remove '.', '?', '!', ';' or "-" signs at the end
- if (arrayOfExpressions[i][arrayOfExpressions[i].Length - 1] == '.' || arrayOfExpressions[i][arrayOfExpressions[i].Length - 1] == '?' || arrayOfExpressions[i][arrayOfExpressions[i].Length - 1] == '!' || arrayOfExpressions[i][arrayOfExpressions[i].Length - 1] == ';' || arrayOfExpressions[i][arrayOfExpressions[i].Length - 1] == '-')
- { arrayOfExpressions[i] = arrayOfExpressions[i].Remove(arrayOfExpressions[i].Length-1, 1); }
- Console.WriteLine("{0}", arrayOfExpressions[i]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement