Jump to content
Tuts 4 You
Sign in to follow this  
X-88

[ask, Delphi] how to extract URLs from TMemo

Recommended Posts

X-88

how to get URLs in memo, delimited text or split?

e.g:

in memo.text :

begin

memo1.lines.text := '

rtadgjkjuouioop hxxp://exmpl.com yyhfhjjj

ijoo hxxp://wxw.exmpl.org iolvb

wxw.exmpl.comiiij

fiuddhity

ftp://exmpl.com

uiufsftgco45788

hxxps://exmpl.com

ggcghj

hxxps://wxw.exmpl.net giiu';

end;

result in memo 2

I mean like this code:

function spliter(const s : string; ts, rs : tstrings) : string;

var

i : integer;

begin

for i := 0 to rs.count - 1 do

begin

if (pos('wxw', ts.strings) > 0) or

(pos('fxp://', ts.strings) > 0) or

(pos('hxxp://', ts.strings) > 0) or

(pos('hxxps://', ts.strings) > 0) or

(pos('hxxp://wxw', ts.strings) > 0) or

(pos('hxxps://wxw', ts.strings) > 0) then

begin

result := '';

blah blah blah

etc

end;

rs.text := result;

end;

on button click

spliter(edit1.text, memo1.lines, memo2.lines);

Share this post


Link to post
NOP

Use a regular expression instead of multiple compares


 


something like this works great for a URL... (From RegexBuddys library)



\b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[A-Z0-9+&@#/%=~_|]

But beware, a regex or any sort of compare will never be 100% accurate for a URL because a URL can contain most characters, especially if you are trying to filter spam and the poster is trying to bypass the filter...


Share this post


Link to post
X-88

OK i'll try it.

Share this post


Link to post
X-88

how do I in order to get results this way? for s: =

'<a href="' to'">' do

Share this post


Link to post
NOP

I'm not sure what you asking but if your asking how to match / extract the link in your example ' to' then use a regex again, something like this...



a.?href="'(.+)'"

Share this post


Link to post
X-88

oh sorry still chaos pharsing html script :(

Edited by X-88 (see edit history)

Share this post


Link to post
Departure

if you want to use pos then use it with the '://' string - 4 chars for the beginning and the last '.' + 3 chars for the end per line, this should yield full url. regular expressions would be the best way for this and the more correct way to do it.


Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
×
×
  • Create New...