RegExp \W Metacharacter (uppercase W) - Javascript RegExp

Javascript examples for RegExp:Metacharacter

Description

The \W metacharacter matches a non-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 non-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() {//  w  w  w .j  a  v  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