2011-07-13 12 views
0

IMG SRCのURLをstringXMLから取得しています。 (すなわちhttp://www.webserver.com/picture.jpgvbscript regex get img src URL

これは私が持っているものですが、それは私だけの真/偽を与えている:

<% 
stringXML="<a href="http://www.webserver.com/"><img src="http://www.webserver.com/picture.jpg"/></a><br>Some text here, blah blah blah." 

Dim objRegex 
    Set objRegex = New Regexp 
     With objRegEx 
      .IgnoreCase = True 
      .Global = True 
      .Multiline = True 
    End with 

strRegexPattern = "\<img\s[^\>]*?src=[""'][^\>]*?(jpg|bmp|gif)[""']" 


objRegEx.Pattern = strRegexPattern 

     response.write objRegEx.Test(stringXML) 

If objRegEx.Test(stringXML) = True Then 
    'The string has a tags. 

    'Match all A Tags 
    Set objRegExMatch = objRegEx.Execute(stringXML) 

    If objRegExMatch.Count > 0 Then 
     Redim arrAnchor(objRegExMatch.Count - 1) 
     For Each objRegExMatchItem In objRegExMatch 
      response.write objRegExMatchItem.Value 
     Next 
    End If 
End If 
%> 

私は基本的にONLY IMG SRC値を取得したいが...

任意のアイデア理由この行は動作していません 'response.write objRegExMatchItem.Value'?

乾杯、 ドリュー

答えて

1

試してみてください。

Function getImgTagURL(HTMLstring) 
    Set RegEx = New RegExp 
    With RegEx 
     .Pattern = "src=[\""\']([^\""\']+)" 
     .IgnoreCase = True 
     .Global = True 
    End With 

    Set Matches = RegEx.Execute(HTMLstring) 
    'Iterate through the Matches collection. 
    URL = "" 
    For Each Match in Matches 
     'We only want the first match. 
     URL = Match.Value 
     Exit For 
    Next 
    'Clean up 
    Set Match = Nothing 
    Set RegEx = Nothing 
    ' src=" is hanging on the front, so we will replace it with nothing 
    getImgTagURL = Replace(URL, "src=""", "") 
End Function 
+0

サイコーありがとうございました!!これはちょうどGoogleの検索と試行錯誤の多くの時間を解決しました。再度、感謝します!!! – Drew

+0

1つの問題は、これがCSSとScriptタグでも機能し、今修正しようとしていることです。 –