Advertisement
Guest User

Replace Tag

a guest
May 14th, 2015
414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _02.ReplaceTag
  8. {
  9.     class ReplaceTag
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string input = "<ul><li><a href=http://softuni.bg>SoftUni</a></li></ul>";
  14.             string pattern = @"<a.*?href=(.*?)>(.*?)<\/a>";
  15.             Regex regex = new Regex(pattern);
  16.             MatchCollection matches = regex.Matches(input);
  17.             foreach (Match item in matches)
  18.             {
  19.                 string url = item.Groups[1].ToString();
  20.                 string text = item.Groups[2].ToString();
  21.                 regex.Replace(input, item.ToString());
  22.                 string replace = @"[URL href="+item.Groups[1] + "]"+ item.Groups[2] + "[/URL]";
  23.                 Console.WriteLine(Regex.Replace(input,pattern,replace));
  24.             }
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement