NastySwipy

Prog. Fundam. Exam-09.July.17 Part1- 03. Regexmon

Jun 5th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace _12._ExamPreparation1
  7. {
  8.     class ExamPreparation1
  9.     {
  10.       static void Main(string[] args)
  11.         {
  12.             string input = Console.ReadLine();
  13.             string bojomonPattern = @"([A-Za-z]+)-([A-Za-z]+)";
  14.             string didimonPattern = @"[^A-Za-z-]+";
  15.  
  16.             while (true)
  17.             {
  18.                 Match didimon = Regex.Match(input, didimonPattern);
  19.  
  20.                 if (didimon.ToString() != string.Empty)
  21.                 {
  22.                     Console.WriteLine(didimon.ToString());
  23.                     input = GetSubstring(input, didimon.ToString());
  24.  
  25.                     Match bojomon = Regex.Match(input, bojomonPattern);
  26.  
  27.                     if (bojomon.ToString() != string.Empty)
  28.                     {
  29.                         Console.WriteLine(bojomon.ToString());
  30.                         input = GetSubstring(input, bojomon.ToString());
  31.                     }
  32.                 }
  33.                 else
  34.                 {
  35.                     break;
  36.                 }
  37.             }
  38.         }
  39.  
  40.         static string GetSubstring(string input, string matchedString)
  41.         {
  42.             var stringPosition = input.IndexOf(matchedString);
  43.             var stringLenght = matchedString.Length;
  44.             var cutsFrom = stringPosition + stringLenght;
  45.             input = input.Substring(cutsFrom);
  46.             return input;
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment