JavaScript RegExp \s Modifier

Definition and Usage

When the \s modifier is set the regular expression finds single space characters.
A single space character can be:
  • A whitespace character
  • A tab character
  • A carriage return character
  • A new line character
  • A vertical tab character
  • A form feed character




In the following code we will do a global search for the single space characters:

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

The white spaces in the text below will get a match:

Is this all there is?
JavaScript RegExp \s Modifier Reviewed by 1000sourcecodes on 21:50 Rating: 5
Powered by Blogger.