JavaScript RegExp \s Metacharacter

JavascriptObject Oriented ProgrammingFront End Technology

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

Example

// Not containing any white spaces:
console.log(/\s/.test("1"))
console.log(/\s/.test("test"))
// Containing whitespace characters:
console.log(/\s/.test(" "))
console.log(/\s/.test("a\tb"))
console.log(/\s/.test("m\nn"))

Output

false
false
true
true
true
raja
Published on 18-Sep-2019 12:26:19
Advertisements