JavaScript RegExp \W Metacharacter

JavascriptObject Oriented ProgrammingFront End Technology

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
raja
Published on 18-Sep-2019 12:32:45
Advertisements