Why here we have non-alphabetical and non-numerical results?

I think because “w” is a capital letter it should just return “C”. But it does not!??

let shortHand = /\W/;
let numbers = "42%";
let sentence = "Coding!";
numbers.match(shortHand); // Returns ["%"]
sentence.match(shortHand); // Returns ["!"]

Hey @najme,

Capital W i.e. /\W/ matches any character that is not a word character. Here, word includes alphanumeric characters.

If you had small w i.e. /\w/ matches any word character that means opposite of the above case.

Also, whenever i have to do and understand regex, i head over to https://regexr.com/

It’s pretty helpful in understanding regex.
Hope this helps.

1 Like

Thank you so much :slight_smile: