# Invert Regular Expression Matches with JavaScript

**URL:** <https://forum.freecodecamp.org/t/invert-regular-expression-matches-with-javascript/155552>\
**Category:** General\
**Created:** [October 28, 2017, 4:48am UTC](https://forum.freecodecamp.org/t/invert-regular-expression-matches-with-javascript/155552 "2017-10-28T04:48:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shubham1507](https://avatars.discourse-cdn.com/v4/letter/s/b3f665/32.png) [@shubham1507](https://forum.freecodecamp.org/u/shubham1507)\
**Post date:** [October 28, 2017, 4:48am UTC](https://forum.freecodecamp.org/t/invert-regular-expression-matches-with-javascript/155552/1 "2017-10-28T04:48:44Z")

</div>

**Tell us what’s happening:**

**Your code so far**

```auto
// Setup
var testString = "How many non-space characters are there in this sentence?";

// Only change code below this line.

var expression = /\s/g; // Change this line

// Only change code above this line

// This code counts the matches of expression in testString
var nonSpaceCount = testString.match(expression).length;

```

**Your browser information:**

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

**Link to the challenge:**  
[https://www.freecodecamp.org/challenges/invert-regular-expression-matches-with-javascript](https://www.freecodecamp.org/challenges/invert-regular-expression-matches-with-javascript)

---

<div class="post-metadata">

**Author:** ![LightningCoding](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/lightningcoding/32/67717_2.png) [@LightningCoding](https://forum.freecodecamp.org/u/LightningCoding)\
**Post date:** [October 28, 2017, 8:11pm UTC](https://forum.freecodecamp.org/t/invert-regular-expression-matches-with-javascript/155552/2 "2017-10-28T20:11:53Z")

</div>

You used /\s/g , so your code will match all whitespace characters.

Take a look at the information in the top-right corner:

> For example, \s will match any whitespace, and \S will match anything that isn’t whitespace.

Now take a closer look at the instructions:

> Use /\S/g to count the number of non-whitespace characters in testString

So you have to use /\S/g to match all **non** -whitespace characters.

---

<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 17, 2021, 8:36pm UTC](https://forum.freecodecamp.org/t/invert-regular-expression-matches-with-javascript/155552/3 "2021-01-17T20:36:07Z")

</div>


