JavaScript RegExp W Metacharacter


The \W metacharacter is used to find a non-word character.

A word character is a character from a-z, A-Z, 0-9, including the _ (underscore) character.

Example

// Containing any non word character:
console.log(/\W/.test(" "))
console.log(/\W/.test(".!@#"))
// Not containing non word characters:
console.log(/\W/.test("a"))
console.log(/\W/.test("B"))
console.log(/\W/.test("9"))
console.log(/\W/.test("_"))

Output

true
true
false
false
false
false

Updated on: 18-Sep-2019

177 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements