Advertisement
martinvalchev

Key_Replacer

Feb 25th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 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 Key_Replacer
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string pattern = @"([A-Za-z]+)([<\|\\])(.*)([<\|\\])([A-Za-z]+)";
  15.             string input = Console.ReadLine();
  16.             Match myMatch = Regex.Match(input, pattern);
  17.             string start = myMatch.Groups[1].Value;
  18.             string end = myMatch.Groups[5].Value;
  19.             string input2 = Console.ReadLine();
  20.             string pattern2 = $@"{start}(.*?){end}";
  21.             StringBuilder stringBuilder = new StringBuilder();
  22.  
  23.             MatchCollection results = Regex.Matches(input2, pattern2);
  24.  
  25.             foreach (Match m in results)
  26.             {
  27.                 stringBuilder.Append(m.Groups[1].Value);
  28.             }
  29.            
  30.             if (stringBuilder.ToString().Length == 0)
  31.             {
  32.                 Console.WriteLine("Empty result");
  33.             }
  34.             else
  35.             {
  36.                 Console.WriteLine(stringBuilder);
  37.             }
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement