'التابع
Public Function ParseImages(ByVal HTML As String) As ArrayList
' Remember to add the following at top of class:
' - Imports System.Text.RegularExpressions
Dim objRegEx As System.Text.RegularExpressions.Regex
Dim objMatch As System.Text.RegularExpressions.Match
Dim arrLinks As New System.Collections.ArrayList()
' Create regular expression
objRegEx = New System.Text.RegularExpressions.Regex( _
"img.*src\s*=\s*(?:""(?<1>[^""]*)""|(?<1>\S+))", _
System.Text.RegularExpressions.RegexOptions.IgnoreCase Or _
System.Text.RegularExpressions.RegexOptions.Compiled)
' Match expression to HTML
objMatch = objRegEx.Match(HTML)
' Loop through matches and add <1> to ArrayList
While objMatch.Success
Dim strMatch As String
strMatch = objMatch.Groups(1).ToString
arrLinks.Add(strMatch)
objMatch = objMatch.NextMatch()
End While
' Pass back results
Return arrLinks
End Function
'في أي مكان أكتب
Dim Htl As String = My.Computer.FileSystem.ReadAllText("c:\1.htm")
Dim Links As ArrayList = ParseImages(Htl)
Dim LinksCol As String
For Each LinksCol In Links
MsgBox(LinksCol)
Next