Advertisement
Guest User

Untitled

a guest
Oct 29th, 2017
510
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace _05.KeyReplacer
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string keyInput = Console.ReadLine();
  11.             string textInput = Console.ReadLine();
  12.  
  13.             string patern = $@"^([a-zA-Z]+)[\\|\\<\\\\](.+)[\\|\\<\\\\]([a-zA-Z]+)$";
  14.             Regex regex = new Regex(patern);
  15.  
  16.             Match match = regex.Match(keyInput);
  17.             string start = match.Groups[1].Value;
  18.             string end = match.Groups[3].Value;
  19.  
  20.             string wordPattern = $@"{start}(?!{end})(.*?){end}";
  21.             MatchCollection matchCollection = Regex.Matches(textInput, wordPattern);
  22.  
  23.             if (matchCollection.Count > 0)
  24.             {
  25.                 foreach (Match item in matchCollection)
  26.                 {
  27.                     Console.Write(item.Groups[1].Value);
  28.                 }
  29.                 Console.WriteLine();
  30.             }
  31.             else
  32.             {
  33.                 Console.WriteLine("Empty result");
  34.             }
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement