Regular Expressions - Specify Upper and Lower Number of Matches

Do we need the \s for the space? I did not include it and it was “approved” as a correct solution. Thanks!

let ohStr = "Ohhh no";
let ohRegex = /Oh{3,6} no/; // Change this line
let result = ohRegex.test(ohStr);

Your browser information:

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

Challenge: Regular Expressions - Specify Upper and Lower Number of Matches

Link to the challenge:

you are matching the space with the space character in your regex, \s matches [ \t\r\n\f] which includes the space character

As said it wouldn’t match against other types of spaces, like a tab, which \s would.

let ohStr = "Ohhh	no";
let ohRegex = /Oh{3,6} no/; // Change this line
let result = ohRegex.test(ohStr);
console.log(result) // false

let ohStr = "Ohhh	no";
let ohRegex = /Oh{3,6}\sno/; // Change this line
let result = ohRegex.test(ohStr);
console.log(result) // true

Character classes

\s Matches a single white space character, including space, tab, form feed, line feed, and other Unicode spaces. Equivalent to [ \f\n\r\t\v\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]. For example, /\s\w*/ matches " bar" in “foo bar”.


It should be noted the string inside the ohStr variable in the editor can be changed and the tests will still pass (as long as the regex is correct). But you can log out result to test it.