Solved

Extracting web links from string

Posted on 2004-04-24
8
327 Views
Last Modified: 2010-04-05
Hello,

How can I extract web links from string, for example I have string with web links and other text and I need only those web links that match special code or text.
0
Comment
Question by:H-styler
8 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 10907060

I advise regular expressions.

Freeware for Delphi
http://regexpstudio.com/TRegExpr/TRegExpr.html
0
 
LVL 17

Expert Comment

by:mokule
ID: 10907068

This is an example of regular expression from TRegExpr test program for extracting URL from text.

(?i)                          # we need caseInsensitive mode
(FTP|HTTP)://                 # protocol
([_a-z\d\-]+(\.[_a-z\d\-]+)+) # TCP addr
((/[ _a-z\d\-\\\.]+)+)*       # unix path
0
 
LVL 3

Accepted Solution

by:
Kunfufaresi earned 50 total points
ID: 10907298
Hello, not as fancy as regex but you could use this code

s:String;
i :integer;

begin
 s := texttoparse;
 repeat
  i := pos('http://',s);
  if i>0 then
  begin
   delete(s,1,i-1);
   i := pos(' ');
   if i=0 then i := length(s)+1;
   listbox1.items.add(copy(s,1,i-1)); // so the url is = copy(s,1,i-1)
   delete(s,1,i);
  end;
 until i=0;
end;

well this would work if your urls doesnt contain spaces which they shouldnt as spaces are encoded already.

Kunfu Faresi
0
 
LVL 17

Expert Comment

by:mokule
ID: 10907314
I advise regexpr because he wrote
"I need only those web links that match special code or text."
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 3

Expert Comment

by:Kunfufaresi
ID: 10907605
Yes you are right, regexp is much more advanced, but i've used it some times and still have not gotten all the hang of it.
0
 

Author Comment

by:H-styler
ID: 10908088
Kunfufaresi with your code I can`t extract links from this type of string:

<table border=0 cellpadding=0 cellspacing=0 bgcolor=ffffff><tr><td><a href="http://www.bythebeachemails.com/scripts/runner.php?PA=116" target=_ptc onclick="javascript:reloadpage(30)"><img src=http://www.bythebeachemails.com/scripts/runner.php?REDIRECT=http%3A%2F%2Fmpam2.free.fr%2Fcash%2Fbann_cash2.gif alt="Great PTR/PTC sites" width=468 height=60 border=0></a></td></tr></table>The ad above is worth 50 cent(s)<br><br><br><br><br><b>1</b><br> <br>

And I only need to extract those links witch match for example this code: "scripts/runner.php?PA="
0
 
LVL 3

Expert Comment

by:Kunfufaresi
ID: 10908442
Hello,

well if you did a

if pos('scripts/runner.php?PA=',copy(s,1,i-1))>0 then listbox1.items.add(copy(s,1,i-1));

also you should in this case look for pos('"',s) instead of pos(' ',s) as " terminates the url not space.
0
 
LVL 4

Expert Comment

by:ceoworks
ID: 10932036
As mokule said i suggest you to use regular expressions. Here is some usefull stuff http://www.regular-expressions.info/ and if you will search for regular expressions in www.torry.ru, you may found some freeware components.

Regards,
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Strange message in Delphi 10 Seattle 1 463
System restore point 4 77
ddeman not working in activex 3 78
Newbie Thread Programming 1 116
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now