954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

regular expressions

please help!
i am parsing html of a site in c#.net and i need to get the img, object, and applet tags from the html to verify if they have alt or longdesc attributes. please help me...

mjzammit
Newbie Poster
22 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
 

Please don't make your questions such a puzzle. You mention Regular Expressions in the subject, and "parsing HTML" in the post. You need to "get" certain tags. You need help. There is no question per se in your post. Instead of giving us clues pointing vaguely toward a possible question, why not just ask a clear, specific question?

How, exactly, are you "parsing" the HTML? Are you reading the raw HTML via a Stream? Using an HTML DOM object? What does RegEx have to do with this?

tgreer
Made Her Cry
Team Colleague
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
 

I am reading raw html via a stream and need to look for the tags such as, img, object, and applet to check they have any alt attributes. I am using regular expressions.

i was using this regular expression to find images :
"[^\"]*)\"|(?<1\\S+))" but it doesnt work

mjzammit
Newbie Poster
22 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
 

in other words i would like to match an HTML tag with a certain attribute value.
I am new to regular expression.

mjzammit
Newbie Poster
22 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
 

>"[^\"]*)\"|(?<1\\S+))" but it doesnt work
Erm, why not just this?

private HasAttribute ( string src, string tag, string attribute )
{
  string query = "<" + tag + ".+" + attribute + ".+>";

  //...
}

All you're doing is checking a specific tag to see if it has an alt attribute, right?

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

I am reading raw html via a stream and need to look for the tags such as, img, object, and applet to check they have any alt attributes. I am using regular expressions.

i was using this regular expression to find images : "[^\"]*)\"|(?<1\\S+))" but it doesnt work

I understand. Regular Expressions are tough and I always resort to trial and error, and use http://www.regular-expressions.info as a good learning resource. RegEx, however, may not be the best approach in this case. RegEx is used to find and even alter strings. I don't think RegEx will solve the problem of finding tags that are missing attributes.

I would use basic string functions for this, searching for my target tag and then searching for the alt attribute within the tag.

tgreer
Made Her Cry
Team Colleague
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
 

I see.
So i should use a regular expressions to find the image, obect, and applet tags, put the tag's contents on a list and parse each one on the list to check if they have the specific attribute?

mjzammit
Newbie Poster
22 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
 

Is there a regular expression to be able to pull out tags, along with their attributes out of html documents?

mjzammit
Newbie Poster
22 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You