473,378 Members | 1,133 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

[VB.NET express 2005] - Regular expressions

Hi

I'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
Jan 14 '06 #1
5 1566
"Movie Maniac®"
<is*************************@PUSSAVIABRUTTOSPIDERh otmail.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'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jan 14 '06 #2
Herfried K. Wagner [MVP] ha scritto:
"Movie Maniac®"
<is*************************@PUSSAVIABRUTTOSPIDERh otmail.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'.


ok, this should return an array of matches, right?
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
Jan 14 '06 #3

"Movie Maniac®"
<is*************************@PUSSAVIABRUTTOSPIDERh otmail.com> wrote in
message news:43**********************@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?
Jan 14 '06 #4
Homer J Simpson ha scritto:
"Movie Maniac®"
<is*************************@PUSSAVIABRUTTOSPIDERh otmail.com> wrote in
message news:43**********************@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?

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
Jan 15 '06 #5

"Movie Maniac®"
<is*************************@PUSSAVIABRUTTOSPIDERh otmail.com> wrote in
message news:43**************@PUSSAVIABRUTTOSPIDERhotmail. com...
<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?


To match

<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.

Jan 15 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: matt cook | last post by:
The concept - a HTML file changes regularly. However, only certain parts of the page change. I want to find a regular expression that describes that changed area. Can anyone here think of a...
5
by: Drew | last post by:
We have a string like: 2004\05\05T00:00:00 We would like to remove all "\", any "-" and the T00:00:00 part of the string. The end result would be 20040505. I know that if I use as the...
2
by: Sehboo | last post by:
Hi, I have several regular expressions that I need to run against documents. Is it possible to combine several expressions in one expression in Regex object. So that it is faster, or will I...
4
by: Együd Csaba | last post by:
Hi All, I'd like to "compress" the following two filter expressions into one - assuming that it makes sense regarding query execution performance. .... where (adate LIKE "2004.01.10 __:30" or...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
9
by: HC | last post by:
Hello, all, I started out thinking my problems were elsewhere but as I have worked through this I have isolated my problem, currently, as a difference between MSDE and SQL Express 2005 (I'll just...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.