Advertisement
vencinachev

RegEx

Mar 9th, 2021
865
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.28 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace RegEx
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string email = "ivan@abvbg";
  15.             string regex = @"^[a-zA-Z_0-9]+@[a-zA-Z]+\.[a-z]{2,3}$";
  16.             Match m = Regex.Match(email, regex);
  17.             if (m.Success)
  18.             {
  19.                 Console.WriteLine("Valid email!");
  20.             }
  21.             else
  22.             {
  23.                 Console.WriteLine("Invalid email!");
  24.             }
  25.             /*string doc = "Smith's number: 0898880022\nFranky can be " +
  26.       " found at 0888445566.\nSteven’ mobile number: 0887654321";
  27.  
  28.             string replacedDoc = Regex.Replace(doc, "(08)[0-9]{8}", "$1********");
  29.             Console.WriteLine(replacedDoc);*/
  30.  
  31.             /*string pattern = @"\b[M]\w+";
  32.             Regex rg = new Regex(pattern);
  33.             string authors = "Mahesh Chand, Raj Kumar, Mike Gold, Allen O'Neill, Marshal Troll";
  34.             MatchCollection matchedAuthors = rg.Matches(authors);
  35.             foreach (var item in matchedAuthors)
  36.             {
  37.                 Console.WriteLine(item);
  38.             }*/
  39.         }
  40.     }
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement