Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

RegExp \W metacharacter

JavaScript RegExp \W metacharacter

RegExp Object Reference JavaScript RegExp Object


Definition and Usage

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

Word characters include: a-z, A-Z, 0-9, and the underscore.

Syntax

new RegExp("\W")

Or a simpler way:

/\W/


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the \W metacharacter


Example

Example

Perform a global search for non-word characters in the string:

var str="Give 100%!";

var patt1=/\W/g;

The text marked below shows where the expression found matches:

Give 100

%!

Try it »


RegExp Object Reference JavaScript RegExp Object