Skip to content

Instantly share code, notes, and snippets.

@yavgel85
Created March 26, 2021 11:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yavgel85/d1d36bede5c04af367c38f4cdfa33d4c to your computer and use it in GitHub Desktop.
Save yavgel85/d1d36bede5c04af367c38f4cdfa33d4c to your computer and use it in GitHub Desktop.
getBaseURL #js #browser
// Gets the current URL without any parameters or fragment identifiers.
// Use String.prototype.replace() with an appropriate regular expression to remove everything after either '?' or '#', if found.
const getBaseURL = url => url.replace(/[?#].*$/, '');
// Examples
getBaseURL('http://url.com/page?name=Adam&surname=Smith'); // 'http://url.com/page'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment