Advertisement
North_Point

03. Regexmon

Aug 16th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 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 _03
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             var boyPattern = @"[A-Za-z]+\-[A-Za-z]+";
  15.             var girlPattern = @"[^A-Za-z\-]+";
  16.  
  17.             var input = Console.ReadLine();
  18.             while (true)
  19.             {
  20.                 var girlMatches = Regex.Match(input, girlPattern);
  21.                 if (!Regex.IsMatch(input, girlPattern))
  22.                 {
  23.                     break;
  24.                 }
  25.                 input = input.Remove(0, girlMatches.Index + girlMatches.Length);
  26.                 Console.WriteLine(girlMatches);
  27.                
  28.                 var boyMatches = Regex.Match(input, boyPattern);
  29.                 if (!Regex.IsMatch(input, boyPattern))
  30.                 {
  31.                     break;
  32.                 }
  33.                 Console.WriteLine(boyMatches);
  34.                 input = input.Remove(0, boyMatches.Index + boyMatches.Length);
  35.                
  36.                
  37.             }
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement