regular expressions

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2008
Posts: 22
Reputation: mjzammit is an unknown quantity at this point 
Solved Threads: 0
mjzammit mjzammit is offline Offline
Newbie Poster

regular expressions

 
0
  #1
Apr 24th, 2008
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...
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 1,655
Reputation: tgreer is an unknown quantity at this point 
Solved Threads: 35
Team Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: regular expressions

 
0
  #2
Apr 24th, 2008
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?
Last edited by tgreer; Apr 24th, 2008 at 6:20 pm.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 22
Reputation: mjzammit is an unknown quantity at this point 
Solved Threads: 0
mjzammit mjzammit is offline Offline
Newbie Poster

Re: regular expressions

 
0
  #3
Apr 25th, 2008
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 :
"<img.*src\\s*=\\s*(?:\"(?<1>[^\"]*)\"|(?<1\\S+))" but it doesnt work
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 22
Reputation: mjzammit is an unknown quantity at this point 
Solved Threads: 0
mjzammit mjzammit is offline Offline
Newbie Poster

Re: regular expressions

 
0
  #4
Apr 25th, 2008
in other words i would like to match an HTML tag with a certain attribute value.
I am new to regular expression.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,614
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 713
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: regular expressions

 
0
  #5
Apr 25th, 2008
>"<img.*src\\s*=\\s*(?:\"(?<1>[^\"]*)\"|(?<1\\S+))" but it doesnt work
Erm, why not just this?
  1. private HasAttribute ( string src, string tag, string attribute )
  2. {
  3. string query = "<" + tag + ".+" + attribute + ".+>";
  4.  
  5. //...
  6. }
All you're doing is checking a specific tag to see if it has an alt attribute, right?
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 1,655
Reputation: tgreer is an unknown quantity at this point 
Solved Threads: 35
Team Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: regular expressions

 
0
  #6
Apr 25th, 2008
Originally Posted by mjzammit View Post
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 :
"<img.*src\\s*=\\s*(?:\"(?<1>[^\"]*)\"|(?<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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 22
Reputation: mjzammit is an unknown quantity at this point 
Solved Threads: 0
mjzammit mjzammit is offline Offline
Newbie Poster

Re: regular expressions

 
0
  #7
Apr 25th, 2008
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?
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 22
Reputation: mjzammit is an unknown quantity at this point 
Solved Threads: 0
mjzammit mjzammit is offline Offline
Newbie Poster

Re: regular expressions

 
0
  #8
Apr 25th, 2008
Is there a regular expression to be able to pull out tags, along with their attributes out of html documents?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC