|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
[VB.NET express 2005] - Regular expressionsI'm writing a little app and I need some html parsing through regular expressions. I wrote this piexe of code Private Function findImgTags(ByVal strHTML As String) As Object dim MatchObj As Match = Regex.Match(strHTML, "<img[^>]*>", RegexOptions.IgnoreCase) return MatchObj End Function This should return an object containing all the img tags, unfortunately returns only the first img :( Plus, I need to parse the whole html and find retain only thos img that contains the string 'edit', as for example: <img src="myimage.gif" title="edit" border="0"> How can I manage to do this? Thanks in advance "Movie Maniac®"
<isotopiPUSSAVIABRUTTOSPI***@PUSSAVIABRUTTOSPIDERhotmail.com> schrieb: > Private Function findImgTags(ByVal strHTML As String) As Object Use 'Regex.Matches' instead of 'Regex.Match'.> dim MatchObj As Match = Regex.Match(strHTML, "<img[^>]*>", > RegexOptions.IgnoreCase) > return MatchObj > End Function > > This should return an object containing all the img tags, unfortunately > returns only the first img :( -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> Herfried K. Wagner [MVP] ha scritto:
Show quoteHide quote > "Movie Maniac®" ok, this should return an array of matches, right?> <isotopiPUSSAVIABRUTTOSPI***@PUSSAVIABRUTTOSPIDERhotmail.com> schrieb: > >> Private Function findImgTags(ByVal strHTML As String) As Object >> dim MatchObj As Match = Regex.Match(strHTML, "<img[^>]*>", >> RegexOptions.IgnoreCase) >> return MatchObj >> End Function >> >> This should return an object containing all the img tags, >> unfortunately returns only the first img :( > > > Use 'Regex.Matches' instead of 'Regex.Match'. So this solves the first question. But, how can I retrieve only those img tag containing the 'edit' string? I know this is more a matter of reg_exp, but hope someone can help :) Thanks "Movie Maniac®"
<isotopiPUSSAVIABRUTTOSPI***@PUSSAVIABRUTTOSPIDERhotmail.com> wrote in message news:43c8f248$0$1085$4fafbaef@reader1.news.tin.it... Can you post a couple of lines?> But, how can I retrieve only those img tag containing the 'edit' string? > I know this is more a matter of reg_exp, but hope someone can help :) Homer J Simpson ha scritto:
> "Movie Maniac®" a couple of lines of what? Of VB code? of html code?> <isotopiPUSSAVIABRUTTOSPI***@PUSSAVIABRUTTOSPIDERhotmail.com> wrote in > message news:43c8f248$0$1085$4fafbaef@reader1.news.tin.it... > > >>But, how can I retrieve only those img tag containing the 'edit' string? >>I know this is more a matter of reg_exp, but hope someone can help :) > > > Can you post a couple of lines? well, as for VB, here you go: Private Function findImgTags(ByVal strHTML As String) As Object 'Returns the img tag we are searching Dim Match = Regex.Matches(strHTML, "<img[^>]*>", RegexOptions.IgnoreCase) Dim str As Object Dim a As String For Each str In Match a = str.ToString() If InStr(a, "edit", CompareMethod.Text) Then Return a Next Return False End Function while if you meant html code, well imagine an html page with a serie of images, like this: <img src="image1.gif" title="join"> <img src="image1.gif" title="leave"> <img src="image1.gif" title="add"> <img src="image1.gif" title="edit"> <img src="image1.gif" title="delete"> I would like to retrieve just the last one. As you can see, I retrieve all the images, and then do a loop on the object to find the right one. But I know I can avoid this with the proper regular expression. The question is: how can I do? Thanks a lot "Movie Maniac®"
<isotopiPUSSAVIABRUTTOSPI***@PUSSAVIABRUTTOSPIDERhotmail.com> wrote in message news:43C990DF.6030109@PUSSAVIABRUTTOSPIDERhotmail.com... To match> <img src="image1.gif" title="join"> > <img src="image1.gif" title="leave"> > <img src="image1.gif" title="add"> > <img src="image1.gif" title="edit"> > <img src="image1.gif" title="delete"> > > I would like to retrieve just the last one. As you can see, I retrieve all > the images, and then do a loop on the object to find the right one. But I > know I can avoid this with the proper regular expression. > The question is: how can I do? <img src="image1.gif" title="delete"> anywhere in the line you need something like \<img src=[^>]* title=\"delete\"\> Can't say this is exactly right but it should be close.
Regional settings cause runtime crash
Images inline with blog contents - HOW?? Referencing "Forms" objects from a module some advice How would I make this into a class ? simple program HELP. Tabbed MDI Interface IO locked error Command.Close vs Command.Dispose Problem on MSHFlexGrid Regarding a dot net application program |
|||||||||||||||||||||||