JavaScript RegExp \w meta character
- Previous Page .
- Next Page \W
- Go to the Previous Level JavaScript RegExp Reference Manual
Definition and usage
\w
Meta characters match word characters.
Word characters are characters a-z, A-Z, 0-9, including _ (underscore).
Instance
Global search for 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 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 .
- Next Page \W
- Go to the Previous Level JavaScript RegExp Reference Manual