--- id: 587d7dbb367417b2b2512bac title: Remove Whitespace from Start and End challengeType: 1 forumTopicId: 301362 --- ## Description
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.
## Instructions
Write a regex and use the appropriate string methods to remove whitespace at the beginning and end of strings. Note
The .trim() method would work here, but you'll need to complete this challenge using regular expressions.
## Tests
```yml tests: - text: result should equal to "Hello, World!" testString: assert(result == "Hello, World!"); - text: You should not use the .trim() method. testString: assert(!code.match(/\.trim\(.*?\)/)); - text: The result variable should not be set equal to a string. testString: assert(!code.match(/result\s*=\s*".*?"/)); ```
## Challenge Seed
```js let hello = " Hello, World! "; let wsRegex = /change/; // Change this line let result = hello; // Change this line ```
## Solution
```js let hello = " Hello, World! "; let wsRegex = /^(\s+)(.+[^\s])(\s+)$/; let result = hello.replace(wsRegex, '$2'); ```