JavaScript RegExp \s meta character
- Previous Page \D
- Next Page \S
- Go to the Previous Level JavaScript RegExp Reference Manual
Definition and usage
\s
Meta characters match whitespace characters.
Whitespace characters can be:
- Space character
- Tab
- Carriage return
- Line feed
- Vertical tab
- Page break
Instance
Global search for whitespace characters:
let text = "Is this all there is?"; let pattern = /\s/g;
Syntax
new RegExp("\\s")
Or abbreviated as:
/\s/
Syntax with modifiers
new RegExp("\\s", "g")
Or abbreviated as:
/\s/g
Browser support
/\s/
It is an ECMAScript1 (ES1) feature.
All browsers fully support ES1 (JavaScript 1997):
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Supported | Supported | Supported | Supported | Supported | Supported |
Regular expression search methods
In JavaScript, regular expression text search can be completed using different methods.
UsagePattern (pattern)As regular expressions, these are the most commonly used methods:
Example | Description |
---|---|
text.match(pattern) | String method match() |
text.search(pattern) | String method search() |
pattern.exec(text) | RexExp method exec() |
pattern.test(text) | RexExp Method test() |
- Previous Page \D
- Next Page \S
- Go to the Previous Level JavaScript RegExp Reference Manual