Files
30-seconds-of-code/snippets/getBaseURL.md
Angelos Chalaris d5269b2353 Update getBaseURL.md
2021-01-03 20:32:13 +02:00

18 lines
428 B
Markdown

---
title: getBaseURL
tags: string,browser,regexp,beginner
---
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.
```js
const getBaseURL = url => url.replace(/[?#].*$/, '');
```
```js
getBaseURL('http://url.com/page?name=Adam&surname=Smith');
// 'http://url.com/page'
```