using System; using System.Text.RegularExpressions;
namespace E { public class Program { private static Regex re = new Regex(@"(?:<a[^>]+href\s*=\s*[""'])([^""']*)(?:[""'][^>]*>)([^<]*)(?:</a>)", RegexOptions.IgnoreCase); public static void Find(string html) { foreach(Match m in re.Matches(html)) { Console.WriteLine("link=" + m.Groups[1].Value); Console.WriteLine("title=" + m.Groups[2].Value); } } public static void Main(string[] args) { Find("bla <a href='foo.html'>Foo</a> bla <a href='bar.html'>Bar</a> bla"); Console.ReadKey(); } } }
Hey Nå, jeg har kigget på det og arne_v's udgave spiller faktisk fint. Men m.Groups[2].Value er selve linkets tekst og ikke title, nogen ideer til hvordan det fikses?
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.