Advertisement
Guest User

Untitled

a guest
Jun 25th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4.  
  5.  
  6. namespace Regexer
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.  
  13.             string lineOne = Console.ReadLine();
  14.             string lineTwo = Console.ReadLine();
  15.             string keyWordsPattern = @"(?<StartKey>^.*?)(?=[|<\\])(.*(?=[|<\\]).{1})(?<EndKey>.*\b)";
  16.  
  17.             Match match = Regex.Match(lineOne, keyWordsPattern);
  18.  
  19.             string startWord = match.Groups["StartKey"].Value;
  20.             string endWord = match.Groups["EndKey"].Value;
  21.             string pattern = $@"{startWord}(.*?)(?={endWord})";
  22.  
  23.             MatchCollection matches = Regex.Matches(lineTwo, pattern);
  24.             Match heya = Regex.Match(lineTwo, pattern);
  25.  
  26.             if (heya.Groups[1].Value == String.Empty)
  27.             {
  28.                 Console.WriteLine("Empty result");
  29.                 return;
  30.             }
  31.  
  32.             foreach (Match word in matches)
  33.             {
  34.                
  35.                 Console.Write(word.Groups[1]);
  36.             }
  37.             Console.WriteLine();
  38.  
  39.  
  40.  
  41.  
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement