2018-10-10 18:03:03 -04:00
---
id: 587d7dbb367417b2b2512bac
title: Remove Whitespace from Start and End
challengeType: 1
2019-08-28 16:26:13 +03:00
forumTopicId: 301362
2018-10-10 18:03:03 -04:00
localeTitle: Удаление пробелов от начала и конца
---
## Description
2019-08-28 16:26:13 +03:00
< section id = 'description' >
Иногда пробельные символы вокруг строк не нужны, но есть. Типичная обработка строк - удаление пробелов в начале и в конце.
< / section >
2018-10-10 18:03:03 -04:00
## Instructions
2019-08-28 16:26:13 +03:00
< section id = 'instructions' >
Напишите регулярное выражение и используйте соответствующие строковые методы для удаления пробелов в начале и в конце строк. < strong > Заметка< / strong > < br > Здесь будет работать метод < code > .trim()< / code > , но вам придется выполнить эту задачу, используя регулярные выражения.
< / section >
2018-10-10 18:03:03 -04:00
## Tests
< section id = 'tests' >
```yml
tests:
2019-08-28 16:26:13 +03:00
- text: < code > result</ code > should equal to < code > "Hello, World!"</ code >
testString: assert(result == "Hello, World!");
- text: You should not use the < code > .trim()</ code > method.
testString: assert(!code.match(/\.trim\(.*?\)/));
- text: The < code > result</ code > variable should not be set equal to a string.
testString: assert(!code.match(/result\s*=\s*".*?"/));
2018-10-10 18:03:03 -04:00
```
< / section >
## Challenge Seed
< section id = 'challengeSeed' >
< div id = 'js-seed' >
```js
let hello = " Hello, World! ";
let wsRegex = /change/; // Change this line
let result = hello; // Change this line
```
< / div >
< / section >
## Solution
< section id = 'solution' >
```js
2019-08-28 16:26:13 +03:00
let hello = " Hello, World! ";
let wsRegex = /^(\s+)(.+[^\s])(\s+)$/;
let result = hello.replace(wsRegex, '$2');
2018-10-10 18:03:03 -04:00
```
2019-08-28 16:26:13 +03:00
2018-10-10 18:03:03 -04:00
< / section >