Re: [VB.NET express 2005] - Regular expressions



Homer J Simpson ha scritto:
"Movie Maniac®" <isotopiPUSSAVIABRUTTOSPIDER@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:43c8f248$0$1085$4fafbaef@xxxxxxxxxxxxxxxxxxxxxx


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?


a couple of lines of what? Of VB code? of html code?

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
.