Solved

Identify web link in a text

Posted on 2011-09-06
1
368 Views
Last Modified: 2012-06-21
Hi Experts,

Well, I need to do something to identify web links in a text using delphi xe.
For example, if I have a text like this:

"Hi, please visite my web sites: www.myweb1.com , myweb2.com"

I need to do a function to get only the web links (2 in this case)

Some idea
Thanks
0
Comment
Question by:alpires
1 Comment
 
LVL 12

Accepted Solution

by:
Hypo earned 500 total points
ID: 36492518
Yeah,
use regular expressions to get a list of matches for an URL-pattern... (see the ListWebLinks example below)...

I got the regular expression in the ListWebLinks by googling... you might want to tweak it depending on how accurate you need the results to be...

/Hypo
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, RegularExpressions;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Memo2: TMemo;
    procedure Memo1Change(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure ListWebLinks(AText : TStrings; ALinks : TStrings);
var i : integer;
    aRegEx : TRegEx;
    aMatches : TMatchCollection;
begin
  aRegEx := TRegEx.Create('((http|ftp|https):\/\/)?[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?');
  aMatches := aRegEx.Matches(AText.Text);
  for i := 0 to aMatches.Count-1 do
    ALinks.Add(aMatches.Item[i].Value);
end;

procedure TForm1.Memo1Change(Sender: TObject);
begin
  Memo2.Lines.Clear;
  ListWebLinks(Memo1.Lines, Memo2.Lines);
end;

end.

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Python multiple IF statements 4 75
mapBully challenge 6 113
drawing animated level bar based on numbers 3 88
how to send memory stream from ics Client To ics server ? 11 80
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
This video teaches viewers about errors in exception handling.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

911 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

23 Experts available now in Live!

Get 1:1 Help Now