2018-10-12 15:37:13 -04:00
|
|
|
---
|
|
|
|
title: Remove Whitespace from Start and End
|
|
|
|
---
|
2019-07-24 00:59:27 -07:00
|
|
|
# Remove Whitespace from Start and End
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
---
|
|
|
|
## Problem Explanation
|
2018-10-12 15:37:13 -04:00
|
|
|
To solve this challenge you simply have to create a regex string that matches any spaces at the beginning or at the end of the string.
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
|
|
|
|
---
|
|
|
|
## Hints
|
|
|
|
|
|
|
|
### Hint 1
|
2018-10-12 15:37:13 -04:00
|
|
|
Think of how you can select substrings at the beginning or end of a string.
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
### Hint 2
|
2018-10-12 15:37:13 -04:00
|
|
|
Think of how you can select whitespace
|
|
|
|
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
---
|
|
|
|
## Solutions
|
|
|
|
|
|
|
|
<details><summary>Solution 1 (Click to Show/Hide)</summary>
|
|
|
|
|
2018-10-12 15:37:13 -04:00
|
|
|
```javascript
|
|
|
|
let hello = " Hello, World! ";
|
|
|
|
let wsRegex = /^\s+|\s+$/g; // Change this line
|
2019-07-24 00:59:27 -07:00
|
|
|
let result = hello.replace(wsRegex, ""); // Change this line
|
2018-10-12 15:37:13 -04:00
|
|
|
```
|
2019-07-24 00:59:27 -07:00
|
|
|
|
|
|
|
</details>
|