2018-10-10 18:03:03 -04:00
---
id: 587d7dbb367417b2b2512bac
2021-02-06 04:42:36 +00:00
title: Remove Whitespace from Start and End
2018-10-10 18:03:03 -04:00
challengeType: 1
2020-08-04 15:14:01 +08:00
forumTopicId: 301362
2021-01-13 03:31:00 +01:00
dashedName: remove-whitespace-from-start-and-end
2018-10-10 18:03:03 -04:00
---
2020-12-16 00:37:30 -07:00
# --description--
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Sometimes whitespace characters around strings are not wanted but are there. Typical processing of strings is to remove the whitespace at the start and end of it.
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
# --instructions--
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Write a regex and use the appropriate string methods to remove whitespace at the beginning and end of strings.
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
**Note:** The `String.prototype.trim()` method would work here, but you'll need to complete this challenge using regular expressions.
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
# --hints--
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
`result` should equal to `"Hello, World!"`
2018-10-10 18:03:03 -04:00
```js
2020-12-16 00:37:30 -07:00
assert(result == 'Hello, World!');
2018-10-10 18:03:03 -04:00
```
2021-02-06 04:42:36 +00:00
Your solution should not use the `String.prototype.trim()` method.
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
2021-02-06 04:42:36 +00:00
assert(!code.match(/\.?[\s\S]*?trim/));
2020-12-16 00:37:30 -07:00
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
The `result` variable should not be set equal to a string.
2018-10-10 18:03:03 -04:00
```js
2020-12-16 00:37:30 -07:00
assert(!code.match(/result\s*=\s*".*?"/));
2018-10-10 18:03:03 -04:00
```
2020-08-04 15:14:01 +08:00
2021-01-13 03:31:00 +01:00
# --seed--
## --seed-contents--
```js
let hello = " Hello, World! ";
let wsRegex = /change/; // Change this line
let result = hello; // Change this line
```
2020-12-16 00:37:30 -07:00
# --solutions--
2021-01-13 03:31:00 +01:00
```js
let hello = " Hello, World! ";
let wsRegex = /^(\s+)(.+[^\s])(\s+)$/;
let result = hello.replace(wsRegex, '$2');
```