# Remove Whitespace from Start and End-gt

**URL:** <https://forum.freecodecamp.org/t/remove-whitespace-from-start-and-end-gt/309331>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [August 26, 2019, 3:30pm UTC](https://forum.freecodecamp.org/t/remove-whitespace-from-start-and-end-gt/309331 "2019-08-26T15:30:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gaurav\_t](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/gaurav_t/32/124220_2.png) [@gaurav\_t](https://forum.freecodecamp.org/u/gaurav_t)\
**Post date:** [August 26, 2019, 3:30pm UTC](https://forum.freecodecamp.org/t/remove-whitespace-from-start-and-end-gt/309331/1 "2019-08-26T15:30:23Z")

</div>

**Tell us what’s happening:**

When i declare wsRegex with space between | and\s it works like so:  
`let wsRegex = /^\s+| \s$/g;`  
if I do not put space : `let wsRegex = /^\s+|\s$/g;` the output has 1 space after Hello World such as for explanatory reason "Hello World! " and not “Hello World!” Not understanding the behavior.

**Your code so far**

```js

let hello = " Hello, World! ";
let wsRegex = /^\s+| \s$/g; // Change this line
let result = hello.replace(wsRegex,'x'); // Change this line
console.log(result)

```

**Your browser information:**

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36`.

**Link to the challenge:**

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/regular-expressions/remove-whitespace-from-start-and-end)**
>
> Learn to Code — For Free

---

<div class="post-metadata">

**Author:** ![lasjorg](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/lasjorg/32/280761_2.png) [@lasjorg](https://forum.freecodecamp.org/u/lasjorg)\
**Post date:** [August 26, 2019, 4:34pm UTC](https://forum.freecodecamp.org/t/remove-whitespace-from-start-and-end-gt/309331/2 "2019-08-26T16:34:41Z")

</div>

You are missing the [quantifier](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Quantifiers) (+) on the “at end” space matching. So without the literal space match you are only matching one space.

```auto
" test".replace(/\s/, '')
" test"

" test".replace(/ \s/, '')
"test"

```

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 25, 2021, 12:19pm UTC](https://forum.freecodecamp.org/t/remove-whitespace-from-start-and-end-gt/309331/3 "2021-01-25T12:19:32Z")

</div>

Closed on January 25, 2021, 12:19pm UTC


