Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text.RegularExpressions;
- namespace text
- {
- class MainClass
- {
- public static void Main(string[] args)
- {
- string input = Console.ReadLine();
- Regex regexForEmail=new Regex(@"(?<=\s)(?<user>(?![_])[A-za-z0-9]+(?:[\.\-_][A-za-z0-9]+)*)@(?<host>[a-zA-Z]+(?:[\-][a-zA-z]+)*(?:\.[a-zA-Z]+(?:[\-][a-zA-Z]+)*)*\.[a-z]+)");// NB! VS is not running regex with "\_"
- MatchCollection matchesEmail = regexForEmail.Matches(input);
- if (regexForEmail.IsMatch(input))
- {
- foreach (Match match in matchesEmail)
- {
- Console.Write(match.Groups["user"]);
- Console.Write("@");
- Console.WriteLine(match.Groups["host"]);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement