Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.30 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4. using System.Linq;
  5.  
  6. namespace SOFTUNI
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string keys = Console.ReadLine();
  13.             string text = Console.ReadLine();
  14.  
  15.             //string KeyStart = Regex.Match(keys, @"^[a-zA-Z]+[<|\\]").ToString();
  16.             //KeyStart = KeyStart.Remove(KeyStart.Length - 1);
  17.             //string KeyEnd = Regex.Match(keys, @"[<|\\][a-zA-Z]+$").ToString().Remove(0, 1);
  18.             string[] keySplit = keys.Split('|', '<', '\\');
  19.             string KeyStart = keySplit[0];
  20.             string KeyEnd = keySplit[keySplit.Length - 1];
  21.  
  22.             //$@"{KeyStart}[a-zA-Z]*?{KeyEnd}"
  23.             //$@"{KeyStart}\w*?{KeyEnd}"
  24.             MatchCollection textMatches = Regex.Matches(text, $@"({KeyStart})+.*?({KeyEnd})+");
  25.             string output = "";
  26.  
  27.             foreach (Match match in textMatches)
  28.             {
  29.                 output += match.ToString().Replace(KeyStart, "").Replace(KeyEnd, "");
  30.             }
  31.  
  32.             if (output != "")
  33.             {
  34.                 Console.WriteLine(output);
  35.             }
  36.             else
  37.             {
  38.                 Console.WriteLine("Empty result");
  39.             }
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement