X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

JavaScript RegExp \S Metacharacter

RegExp Object Reference JavaScript RegExp Object

Example

Do a global search for non-whitespace characters in a string:

var str = "Is this all there is?";
var patt1 = /\S/g;

The marked text below shows where the expression gets a match (matches everything except the whitespaces):

Is this all there is?

Try it yourself »


Definition and Usage

The \S metacharacter is used to find 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

Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The \S metacharacter is supported in all major browsers.


Syntax

new RegExp("\\S")

or simply:

/\S/

Syntax with modifiers

new RegExp("\\S","g")

or simply:

/\S/g


RegExp Object Reference JavaScript RegExp Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook