JavaScript RegExp \sMetacharacter

RegExp 对象参考手册JavaScript RegExp Object

Definition and Usage

The \s metacharacter is used to find whitespace characters.

Whitespace characters can be:

  • Space character
  • Tab character
  • Carriage return character
  • New line character
  • Vertical tab character
  • Form feed character

Syntax

new RegExp("\s")

Or a simpler way:

/\s/


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the \s metacharacter.


Examples

Examples

Perform a global search for whitespace characters in a string:

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

BelowmarkedThe text shows the position where the expression gets a match:

Is this all there is?

Try it Yourself »


RegExp 对象参考手册JavaScript RegExp Object Other Extensions