Advertisement
kot_mapku3

Регулярки.Примеры

Dec 1st, 2017
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Net;
  5. using System.Text.RegularExpressions;
  6.  
  7. namespace Рофл
  8. {
  9.     internal class Program
  10.     {
  11.         public static void Main(string[] args)
  12.         {
  13.             Regex rx = new Regex(@"[a-я]{5,}");
  14.  
  15.             string str = "Здесь много букв, и те, где больше 5 или 5 будут выведены.";
  16.  
  17.             foreach (var temp in rx.Matches(str))
  18.             {
  19.                 Console.WriteLine(temp);
  20.             }
  21.            
  22.             // Теперь поменяем регулярное выражение для этого
  23.             // надо просто переслздать Regex rx, т.е.
  24.             rx = new Regex(@"[A-z0-9]*@[a-z]+\.[a-z]{2,5}"); // Указываем новое регулярное выражение
  25.  
  26.             str = "po4ta@ya.ru";
  27.  
  28.             if (rx.IsMatch(str))
  29.             {
  30.                 Console.WriteLine("Подходит!");
  31.             }
  32.             else
  33.             {
  34.                 Console.WriteLine("Не подходит");
  35.             }
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement