A question about regex shortcuts

Hi all,
This is my solution,

let quoteSample = "The five boxing wizards jump quickly.";
let nonAlphabetRegex = /\W/g; // Change this line
let result = quoteSample.match(nonAlphabetRegex).length;

What I don’t understand is the counting of the special characters. All I see in the above sample is three special characters and the same with the other tests. I don’t see where are the six special characters.
Thank you in advance for your explanation.

Here are the requirements for the test:

Passed
Your regex should find 6 non-alphanumeric characters in “The five boxing wizards jump quickly.”.

Passed
Your regex should use the shorthand character to match characters which are non-alphanumeric.

Passed
Your regex should find 8 non-alphanumeric characters in “Pack my box with five dozen liquor jugs.”

Passed
Your regex should find 6 non-alphanumeric characters in “How vexingly quick daft zebras jump!”

Passed
Your regex should find 12 non-alphanumeric characters in “123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ.”

I got it. The spaces are considered special characters and the quotation marks don’t count as part of the expression.

1 Like

Hello!

\W matches any non-alphanumeric character, which means anything other than a-z0-9_ matches. In this case, the spaces and the dot are matched.

1 Like

@skaparate Hi! Thank you for your kind explanation. I understood it just seconds before your post. Happy coding!

1 Like