Advertisement
Guest User

Key Replacer

a guest
Oct 29th, 2017
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. namespace KeyReplacer
  2. {
  3.     using System;
  4.     using System.Text.RegularExpressions;
  5.  
  6.     public class StartUp
  7.     {
  8.         public static void Main()
  9.         {
  10.             string key = Console.ReadLine();
  11.  
  12.             string text = Console.ReadLine();
  13.  
  14.             string keyPattern = @"^([a-zA-Z]*)[\\<|].{0,}[\\<|]([a-zA-Z]*)$";
  15.  
  16.             Match keyMatches = Regex.Match(key, keyPattern);
  17.  
  18.             string startPattern = keyMatches.Groups[1].Value;
  19.             string endPattern = keyMatches.Groups[2].Value;
  20.  
  21.             string textPattern = @"(" + startPattern + @"(.{0,}?)" + endPattern + @")+";
  22.  
  23.             string result = "";
  24.  
  25.             foreach (Match m in Regex.Matches(text, textPattern))
  26.             {
  27.                result+=m.Groups[2].Value;
  28.             }
  29.  
  30.             if (string.IsNullOrEmpty(result))
  31.             {
  32.                 Console.WriteLine("Empty result");
  33.             }
  34.             else
  35.             {
  36.                 Console.WriteLine(result);
  37.             }
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement