vasildiavolo

05. Key Replacer

May 10th, 2018
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3. using System.Linq;
  4. using System.Globalization;
  5. using System.Numerics;
  6.  
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. string key = Console.ReadLine();
  12. string patternKey = @"(?<start>[a-zA-Z]+)(\||\\|<)((\w*\W*)*(\||\\|<))*(?<end>[a-zA-Z]+)";
  13. string text = Console.ReadLine();
  14. Match matchKey = Regex.Match(key, patternKey);
  15. string start ="{" + matchKey.Groups["start"].Value + "}";
  16. string end = "{" + matchKey.Groups["end"].Value + "}";
  17. string patternText = $@"{start}(?<between>.*?){end}";
  18. MatchCollection matches = Regex.Matches(text, patternText);
  19. string final = null;
  20. foreach (Match item in matches)
  21. {
  22. final+=item.Groups["between"].Value;
  23. }
  24.  
  25. Console.WriteLine(final);
  26.  
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment