0

I want to split the URL till sub directory if available else TLD, How to acheive this using Regex?

www.xyx.com/features.html => www.xyx.com/ to be selected and www.xyx.com/abc/features.html => www.xyx.com/abc/ to be selected

It includes https, http, www and non-www.

Any help appreciated!

Bala
  • 1
  • 1
    What language are you using? – Downgoat Nov 24 '15 at 21:58
  • Is it guaranteed that it will end in `features.html` or even `.html`? – erip Nov 25 '15 at 01:18
  • all pages will end with .html except index.html – Bala Nov 25 '15 at 05:48
  • @Downgoat I am to implement this in javascript. – Bala Nov 25 '15 at 05:54
  • @Bala so you want to split `www.xyx.com/features.html` into `www.xyx.com/` AND `www.xyx.com/abc/`, is that right? – Downgoat Nov 25 '15 at 05:55
  • I need to have the URL till first sub directory if available like www.xyx.com/abc/ from www.xyx.com/abc/def.html (In this the last page with .html has been neglected). Same way for TLD if no sub directory is available then only www.xyx.com/ from www.xyx.com/abc.html. – Bala Nov 25 '15 at 14:31

1 Answers1

-1

Thanks fellas, I have found the answer which I'm unsure is the actual way but satisfies my need.

function myDomains() {
 var str = document.Referrer;
 res = str.split("/");
 var fname = res[3].indexOf(".");
 if(fname > 0) {
  url = res[0]+"//"+res[2];
 } else {
  url = res[0]+"//"+res[2]+"/"+res[3];
 }
 return url;
}

Thanks for the help

Bala
  • 1