using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string input = @" BLANK ATZ Last missing U.S. soldier in Iraq ID'd Go Log in NOT FOUND OK "; string regex = @" ""']|""[^""]*""|'[^']*')*? (?<=\s) href \s* = (?: (?> \s* (['""]) (?.*?) \1 ) | (?> (?!\s*['""]) \s* (?[^\s>]*) (?=\s|>) ) ) (?> (?:"".*?""|'.*?'|[^>]?)+ ) (? (?.*?) "; string output = Regex.Replace(input, regex, "${TEXT} [${URL}]", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace); Console.WriteLine(input + "\n------------\n"); Console.WriteLine(output); } } }