Advertisement
ivanov_ivan

RegexMon - C#

Nov 3rd, 2017
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.89 KB | None | 0 0
  1. namespace ConsoleApp1
  2. {
  3.     using System;
  4.     using System.Text.RegularExpressions;
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string input = Console.ReadLine();
  10.             Regex regD = new Regex(@"[^a-zA-Z-]+");
  11.             Regex regB = new Regex(@"[a-zA-Z]+-[a-zA-Z]+");
  12.             int indexD = 0;
  13.             int indexB = 0;
  14.  
  15.             while (true)
  16.             {
  17.                 Match didimon = regD.Match(input, indexD);
  18.                 if (!didimon.Success) break;
  19.                 Console.WriteLine(didimon.Value);
  20.                 indexB = didimon.Index + didimon.Value.Length;
  21.  
  22.                 Match bojomon = regB.Match(input, indexB);
  23.                 if (!bojomon.Success) break;
  24.                 Console.WriteLine(bojomon.Value);
  25.                 indexD = bojomon.Index + bojomon.Value.Length;
  26.             }
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement