mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jul 2006
Posts: 242
H
HaleyJ Offline OP
Fjord artisan
OP Offline
Fjord artisan
H
Joined: Jul 2006
Posts: 242
Greetings all,

I have three quick questions that I hope the more experienced can help me with.

1.

What is the best way to check if a string is in "www.site.com" format? but not restricted to .com also to .co.uk and others etc

I just want a method to check that a given string is a web URL.

2.

I also want to parse the string incase http:// was added to the string, and want to remove the http:// from the string.

i.e
Code:
echo -a $regex(http://www.google.co.uk/,^^%*(&*%$%$^@%whatever else you geeks put here)
will return "www.google.co.uk" without the http://
I am aware I could use $remove or maybe even tokens, but would like a regex.

3.
If the string contains a URL I just want to return the base URL, not the directories after it. For example http://www.forums.mirc.com/ubbthreads.php?ubb=newpost&Board=5 will return "www.forums.mirc.com"


p.s I wonder if all these questions could be done in one function, like an alias.

One; to check if its in the format "www.site.com" and it not to return false.
Second; if it is a URL but is prefixed by http:// to remove the http:// and return the URL beginning with www.
Third; To return the base URL as mentioned in my previous example.

I hope I have not confused anybody.

Thanks in advance for any replies.


Newbie
Joined: Nov 2009
Posts: 81
V
Babel fish
Offline
Babel fish
V
Joined: Nov 2009
Posts: 81
I wrote a URL-parser and I think "URL" is a broad term.

Try http://www.hawkee.com/snippet/7813/ this snippet. wink

Joined: Jul 2006
Posts: 242
H
HaleyJ Offline OP
Fjord artisan
OP Offline
Fjord artisan
H
Joined: Jul 2006
Posts: 242
Thanks for your reply, but its too broad for what am looking for.


Newbie
Joined: Jul 2006
Posts: 242
H
HaleyJ Offline OP
Fjord artisan
OP Offline
Fjord artisan
H
Joined: Jul 2006
Posts: 242
I will tell you what I have made so far.

Code:
alias parse_url {
  var %url = $$1
  $iif($isid,return,echo -a) $gettok($remove(%url,http://),1,47)
}


Code:
//echo -a $parse_url(http://www.forums.mirc.com/ubbthreads.php?ubb=showflat&Number=225924&page=1&PHPSESSID=26dcb1fe8db39ca7965fd2f9a1e07e94#Post225924)


Returns "www.forums.mirc.com"

Works as intended

Code:
//echo -a $parse_url(https://forums.mirc.com/ubbthreads.php?ubb=showflat&Number=225924&page=1&PHPSESSID=26dcb1fe8db39ca7965fd2f9a1e07e94#Post225924)


Returns "forums.mirc.com"

This does not work as intended as I want the "www.prefix"

More importantly $1 is not checked to see if it is a URL of some form or another.


Newbie

Link Copied to Clipboard