X-88 Posted July 16, 2015 Posted July 16, 2015 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 fiuddhityftp://exmpl.com uiufsftgco45788 hxxps://exmpl.com ggcghj hxxps://wxw.exmpl.net giiu'; end;result in memo 2I 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);
NOP Posted July 17, 2015 Posted July 17, 2015 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...
X-88 Posted July 18, 2015 Author Posted July 18, 2015 how do I in order to get results this way? for s: ='<a href="' to'">' do
NOP Posted July 18, 2015 Posted July 18, 2015 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="'(.+)'"
X-88 Posted July 19, 2015 Author Posted July 19, 2015 (edited) oh sorry still chaos pharsing html script Edited July 20, 2015 by X-88
Departure Posted September 5, 2015 Posted September 5, 2015 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now