Skip to content

Instantly share code, notes, and snippets.

@pastranastevenaz
Created January 10, 2019 22:23
Show Gist options
  • Select an option

  • Save pastranastevenaz/fd5c639130975c64ac84279d3fc572ab to your computer and use it in GitHub Desktop.

Select an option

Save pastranastevenaz/fd5c639130975c64ac84279d3fc572ab to your computer and use it in GitHub Desktop.
Clean a URL with Javascript
cleanUrl: function (dirtyURL){
var a = dirtyURL.toLowerCase();
if (a.startsWith("http") ) {
a = a.split('/')[2];
a = a
.replace('https', '')
.replace('http', '')
.replace('www.', '')
.replace('://', '')
.replace(/\/$/, '')
return a;
} else if(a.startsWith("www.")){
a = a
.replace('https', '')
.replace('http', '')
.replace('www.', '')
.replace('://', '')
.replace(/\/$/, '')
return a;
} else {
return a;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment