RegExp \s Metacharacter - Javascript RegExp

Javascript examples for RegExp:Metacharacter

Description

The \s metacharacter matches a whitespace character.

A whitespace character can be:

  • A space character
  • A tab character
  • A carriage return character
  • A new line character
  • A vertical tab character
  • A form feed character

The following code shows how to Do a global search for whitespace 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 a2  s.  c  o m*/
    var str = "The following code shows how to Is this all there is?";
    var patt1 = /\s/g;
    var result = str.match(patt1);
    document.getElementById("demo").innerHTML = result;
}
</script>

</body>
</html>

Related Tutorials