Mega Code Archive

 
Categories / VB.Net / Development
 

Parse Link and Image tags in a HTML file

Imports System.Collections Public Class MainClass     Public Function ParseLinks(ByVal HTML As String) As ArrayList         Dim objRegEx As System.Text.RegularExpressions.Regex         Dim objMatch As System.Text.RegularExpressions.Match         Dim arrLinks As New System.Collections.ArrayList()         objRegEx = New System.Text.RegularExpressions.Regex( _             "a.*href\s*=\s*(?:""(?<1>[^""]*)""|(?<1>\S+))", _             System.Text.RegularExpressions.RegexOptions.IgnoreCase Or _             System.Text.RegularExpressions.RegexOptions.Compiled)         objMatch = objRegEx.Match(HTML)         While objMatch.Success             Dim strMatch As String             strMatch = objMatch.Groups(1).ToString             arrLinks.Add(strMatch)             objMatch = objMatch.NextMatch()         End While         Return arrLinks     End Function End Class