RegExp \w Metacharacter - Javascript RegExp

Javascript examples for RegExp:Metacharacter

Description

The \w metacharacter matches a word character, which is a character from a-z, A-Z, 0-9, including the _ (underscore) character.

The following code shows how to Do a global search for word characters in a string:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*from   w w  w  .  j av a 2  s  . co  m*/
    var str = "this is 100%!";
    var patt1 = /\w/g;
    var result = str.match(patt1);
    document.getElementById("demo").innerHTML = result;
}
</script>

</body>
</html>

Related Tutorials