freeCodeCamp Challenge Guide: Invert Regular Expression Matches with JavaScript

freeCodeCamp Challenge Guide: Invert Regular Expression Matches with JavaScript
0.0 0

#1

Use/\S/gi; to match everything that isn’t a space in the string.

You can invert any match by using the uppercase version of the selector \s versus \S for example.


#2

Curious…why do we use the (+) plus sign for smaller case /\s+/g but in invert case we are not using the plus sign?


#3

I had the same question and found this:

/\s+/g counts multiple connected spaces as one space. So if it’s even possible, I don’t think there would be a situation for using /\S+/g, since a string would usually contain dissimilar non-space characters.


#4

Here is a link if you want to know more about Regular Expressions.