Advertisement
cap7ainjack

Untitled

Jun 16th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _4_ReplaceTag
  8. {
  9. using System.Text.RegularExpressions;
  10.  
  11. class Program
  12. {
  13. static void Main(string[] args)
  14. {
  15. StringBuilder ads = new StringBuilder();
  16. string readLine = Console.ReadLine();
  17. string output = string.Empty;
  18. while (readLine != "end")
  19. {
  20. ads.Append(readLine);
  21. readLine = Console.ReadLine();
  22. }
  23. string pattern = @"(<ahref=|<a\Whref=|<a\nhref=).+("">).+(<\/a>)";
  24. Regex regex = new Regex(pattern);
  25.  
  26. string replacment1 = "[URL href=";
  27. string replacment2 = "\"]";
  28. string replacmennt3 = "[/URL]";
  29.  
  30. readLine = ads.ToString();
  31. if (regex.IsMatch(readLine))
  32. {
  33. string match1 = regex.Match(readLine).Groups[1].ToString();
  34. output = Regex.Replace(readLine, match1, replacment1);
  35.  
  36. string match2 = regex.Match(readLine).Groups[2].ToString();
  37. output = Regex.Replace(output, match2, replacment2);
  38.  
  39. string match3 = regex.Match(readLine).Groups[3].ToString();
  40. output = Regex.Replace(output, match3, replacmennt3);
  41.  
  42. }
  43.  
  44. Console.WriteLine(output);
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement