JavaScript RegExp \W meta-character
- Previous Page \w
- Next Page \d
- Go to the Previous Level JavaScript RegExp Reference Manual
Definition and usage
\W
Meta-character matches non-word characters:
Word characters are characters a-z, A-Z, 0-9, including _ (underscore).
Instance
Global search for non-word characters:
let text = "Give 100%!"; let pattern = /\W/g;
Syntax
new RegExp("\\W")
Or abbreviated as:
/\W/
Syntax with modifiers
new RegExp("\\W", "g")
Or abbreviated as:
/\W/g
Browser support
/\W/
It is an ECMAScript1 (ES1) feature.
All browsers fully support ES1 (JavaScript 1997):
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Supports | Supports | Supports | Supports | Supports | Supports |
Regular expression search methods
In JavaScript, regular expression text search can be completed with 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 \w
- Next Page \d
- Go to the Previous Level JavaScript RegExp Reference Manual