Latest web development tutorials

RegExp \ w metacharacter

RegExp Object Reference JavaScript RegExp Object

Definition and Usage

\ W metacharacter is used to find a word character.

Word characters include: az, AZ, 0-9, and underscore that contains _ (underscore) character.

grammar

new RegExp("\w")

或者更简单方式:

/\w/


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support \ w metacharacter


Examples

Examples

In a string of characters in a global search for a word:

var str="Give 100%!";
var patt1=/\w/g;

The marked text below shows where the expression gets a match:

Give 100 %!

try it"


RegExp Object Reference JavaScript RegExp Object