Extracting url images from html (regex) Help

alexand83

New Member
Licensed User
Longtime User
Hi i need to extract image url from a parsed string with xmlsax, the xmlsax string dispay me some text with in html code, i need to extract url images from content
Content text is like this:

<p><img align="left" alt="blabla" class="ngg-singlepic ngg-left" height="180" src="http://www.mysite.it/wp-content/gallery/presentazione/logo_mercato_2012-13.jpg" width="300" />Flip-Flip. blabla



I need to take First Url image so this:
http://www.mysite.it/wp-content/gallery/presentazione/logo_mercato_2012-13.jpg

i tried this code for test:

B4X:
pattern = "src=(?:\""|\')?(?<img>[^>]*[^/].(?:jpg|bmp|gif|png))(?:\""|\')?"
      
matcher1 = Regex.Matcher(pattern, test)
      
         Do While matcher1.Find
         Log("Found:" & matcher1.Match)
         
         Loop

but give me an error that pattern isnt correct (test is the content above)

And btw that pattern will show if work

src="http://www.mysite.it/wp-content/gallery/presentazione/logo_mercato_2012-13.jpg

i need it without the scr="

Thanks in advance

Thanks if someone can help me.
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Here:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim s As String = "<img align=""left"" alt=""blabla"" class=""ngg-singlepic ngg-left"" height=""180"" src=""http://www.mysite.it/wp-content/gallery/presentazione/logo_mercato_2012-13.jpg"" width=""300"" />"
   Dim m As Matcher = Regex.Matcher("<img [^>]+ src=\""([^""]+)""", s)
   If m.Find Then
      Log(m.Group(1))
   End If
End Sub
 
Upvote 0
Top