Jag har försökt med Regular Expressions, men jag får inte till det.
Jag försökte till och med en variant av att leta upp första <A med hjälp av Instr och därefter leta upp efterkommande </A> och på så vis ta ut hela <A HREF="http://www.webforum.nu">Besök webforum.nu</A> med hjälp av mid. Hänger ni med? Problemet är när det kommer text varvat mellan urlarna typ.
Alltså, ur en html-kod (<p>Besök gärna <a href="http://www.webforum.nu">webforum.nu</a>, eller varför inte kika in på <a href="http://www.aftonbladet.se">aftonbladet.se</a></p>)
Vill jag hämta ut urlarna och beskrivningarna till länkarna.
Någon som har en lösning eller åtminstone kan ge mig en knuff åt rätt håll?
<%
Dim arrURL()
Dim arrDescription()
i = 0
strText = "Besök gärna <a href=""http://www.webforum.nu"">webforum.nu</a>, eller varför inte kika in på <a href=""http://www.aftonbladet.se"">aftonbladet.se</a>"
Set objRegExp = New RegExp
With objRegExp
.Global = True
.IgnoreCase = True
.Pattern = "<a href=""[^>]+"">"
For Each Match In .Execute(strText)
ReDim Preserve arrURL(i)
arrURL(i) = Mid(Match.Value, 10)
arrURL(i) = Left(arrURL(i), Len(arrURL(i)) - 2)
i = i + 1
Next
i = 0
.Pattern = "<a href=""[^>]+"">[^<]+</a>"
For Each Match In .Execute(strText)
ReDim Preserve arrDescription(i)
arrDescription(i) = Right(Match.Value, Len(Match.Value) - InStr(Match.Value, ">"))
arrDescription(i) = Left(arrDescription(i), Len(arrDescription(i)) - 4)
i = i + 1
Next
End With
Set objRegExp = Nothing
For j = 0 To UBound(arrURL)
Response.Write(arrURL(j) & " - " & arrDescription(j) & "<br>")
Next
%>
<%
Dim arrURL()
Dim arrDescription()
i = 0
strText = "Besök gärna <a href=""http://www.webforum.nu"" class=""blabla""><img src=""bla.gif""></a>, eller varför inte kika in på <a href=""http://www.aftonbladet.se"">aftonbladet.se</a>"
Response.Write("strText = " & Server.HTMLEncode(strText) & "<br><br>")
Set objRegExp = New RegExp
With objRegExp
.Global = True
.IgnoreCase = True
.Pattern = "href=""[^""]*"""
For Each Match In .Execute(strText)
ReDim Preserve arrURL(i)
arrURL(i) = Mid(Match.Value, 7)
arrURL(i) = Left(arrURL(i), Len(arrURL(i)) - 1)
i = i + 1
Next
i = 0
.Pattern = "<a[^>]*>[\w|<img src="".*"">]*</a>"
For Each Match In .Execute(strText)
ReDim Preserve arrDescription(i)
arrDescription(i) = Right(Match.Value, Len(Match.Value) - InStr(Match.Value, ">"))
arrDescription(i) = Left(arrDescription(i), Len(arrDescription(i)) - 4)
i = i + 1
Next
End With
Set objRegExp = Nothing
For j = 0 To UBound(arrURL)
Response.Write(arrURL(j) & " - " & arrDescription(j) & "<br>")
Next
%>