Advertisement
ivanbuhov

HtmlUrlReplacer

Feb 1st, 2013
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.67 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. using System.Text.RegularExpressions;
  7.  
  8. class HtmlUrlReplacer
  9. {
  10.     static void Main()
  11.     {
  12.         string input = "<p>Please visit <a  target = \"_blank\" href  =  \"   http://academy.telerik. com  \"  >our site<  /  a  > to choose a training course. Also visit <a href=\"www.devbg.org\">our forum</a> to discuss the courses.</p>";
  13.         string result = Regex.Replace(input, @"<a[\s][^>]*\bhref\b[\s]*=[\s]*(""|')[\s]*(([^""'])+?)[\s]*\1[\s]*[^>]*[\s]*>([^<]*)<[\s]*/[\s]*a[\s]*>", "[URL=$2]$4[/URL]");
  14.  
  15.         Console.WriteLine(result);
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement