MiscellaneousUser MiscellaneousUser - 10 months ago 65
Vb.net Question

Extract Title from html link

I have the following html string

<a href="/tothepage" title="the page">The Link</a>.

How can i extract title from the HML snippet with ease, either Regex or other. VB.NET solution preferred but C# is ok.

Thanks in advance.

Answer Source

With a regular expression, the group will contain it ([^"]*):



using System.Text.RegularExpressions;
static void Main(string[] args)
        string originalString = "<a href=\" / tothepage\" title=\"the page\">The Link</a>.";
        Regex rgx = new Regex("title=\"([^\"]*)\"", RegexOptions.IgnoreCase);
        Match match = rgx.Matches(originalString)[0];