mIRC Homepage
Posted By: HaleyJ isurl - regex or other method - 13/09/10 11:13 AM
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.
Posted By: Voglea Re: isurl - regex or other method - 13/09/10 11:48 AM
I wrote a URL-parser and I think "URL" is a broad term.

Try http://www.hawkee.com/snippet/7813/ this snippet. wink
Posted By: HaleyJ Re: isurl - regex or other method - 13/09/10 12:13 PM
Thanks for your reply, but its too broad for what am looking for.
Posted By: HaleyJ Re: isurl - regex or other method - 13/09/10 12:34 PM
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.
© mIRC Discussion Forums