RegExp \S Metacharacter (uppercase S) - Javascript RegExp

Javascript examples for RegExp:Metacharacter

Description

The \S metacharacter matches a non-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 non-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() {//from w  w  w.  ja  v a 2 s  .c  o  m
    var str = "this is a test ?";
    var patt1 = /\S/g;
    var result = str.match(patt1);
    document.getElementById("demo").innerHTML = result;
}
</script>

</body>
</html>

Related Tutorials