kidroca

HTML Ancors to MarkDown

May 26th, 2016
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.72 KB | None | 0 0
  1. namespace ReplaceTags
  2. {
  3.     using System;
  4.     using System.Text.RegularExpressions;
  5.  
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             var pattern = new Regex(
  11.                 @"<a\b(?:[^>])*? href=(""|')(?<url>.+?)\1(?:[^>])*?>(?<text>[\W\w]+?)<\/a>",
  12.                 RegexOptions.Multiline);
  13.  
  14.             string text = Console.ReadLine();
  15.             string result = pattern.Replace(text, new MatchEvaluator(ReplacesAncors));
  16.  
  17.             Console.WriteLine(result);
  18.         }
  19.  
  20.         static string ReplacesAncors(Match match)
  21.         {
  22.             return string.Format(
  23.                 "[{0}]({1})", match.Groups["text"].Value, match.Groups["url"]);
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment