Regex, HTML and Certain Links

Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Dec 2008
Posts: 9
Reputation: mawst is an unknown quantity at this point 
Solved Threads: 0
mawst mawst is offline Offline
Newbie Poster

Regex, HTML and Certain Links

 
0
  #1
Dec 19th, 2008
Hello all,

Wondering if someone can direct me to a regex component and some code that I can use to strip out certain links from an HTML file (loading in a StringList).


Example:

<a href="../foo/23134.htm">bar</a>

The result I'm after is:

bar

I only want to strip the link here, but not all links from the page, only ones that contain the ../foo directory in their link. Also, the text within the link needs to stay.

Thanks.
Last edited by mawst; Dec 19th, 2008 at 6:33 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Regex, HTML and Certain Links

 
0
  #2
Dec 19th, 2008
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 9
Reputation: mawst is an unknown quantity at this point 
Solved Threads: 0
mawst mawst is offline Offline
Newbie Poster

Re: Regex, HTML and Certain Links

 
0
  #3
Dec 22nd, 2008
Originally Posted by LizR View Post
http://regexpstudio.com/TRegExpr/TRegExpr.html

<a [^>]*?href="[^"]+?../cathen/*"[^>]*?>(.+?)</a> <--- I need that fixed

That's what I have so far, but the "." and "*" symbols... I'm not sure what I'm doing wrong here.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Regex, HTML and Certain Links

 
0
  #4
Dec 23rd, 2008
I guess you didnt download their studio product to test your regex code on..
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 9
Reputation: mawst is an unknown quantity at this point 
Solved Threads: 0
mawst mawst is offline Offline
Newbie Poster

Re: Regex, HTML and Certain Links

 
0
  #5
Dec 23rd, 2008
Originally Posted by LizR View Post
I guess you didnt download their studio product to test your regex code on..
Ok I'll concede the point. I didn't give the "studio" thing a fair shake. I'm not sure (still) how I managed this but here's the working regex:

<a href="../killthislink/([^>]*?)>(.*?)</a>
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Regex, HTML and Certain Links

 
0
  #6
Dec 23rd, 2008
Regex is a simple but powerful tool. Once you grasp the meaning of bits, it will be very useful and in delphi its one of the fastest methods of searching for non specific text
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 9
Reputation: mawst is an unknown quantity at this point 
Solved Threads: 0
mawst mawst is offline Offline
Newbie Poster

Re: Regex, HTML and Certain Links

 
0
  #7
Dec 23rd, 2008
Originally Posted by LizR View Post
Regex is a simple but powerful tool. Once you grasp the meaning of bits, it will be very useful and in delphi its one of the fastest methods of searching for non specific text
Well I appreciate the help LizR, I can tell that I need to become fluent in this syntax, as you stated it has many applications.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Pascal and Delphi Forum


Views: 1038 | Replies: 6
Thread Tools Search this Thread



Tag cloud for Pascal and Delphi
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC