JavaScript RegExp \b meta character
- Previous Page \S
- Next Page \B
- Go to the Previous Level JavaScript RegExp Reference Manual
Definition and usage
\b
Meta characters match the beginning or end of a word.
Search for the pattern LO at the beginning of the word:
\bLO
Search for the pattern LO at the end of the word:
LO\b
Example
Example 1
Search for "LO" at the beginning of the word:
let text = "HELLO, LOOK AT YOU"; let pattern = /\bLO/;
Example 2
Search for "LO" at the end of the word:
let text = "HELLO, LOOK AT YOU"; let pattern = /LO\b/;
Syntax
new RegExp("\\bregexp)
Or abbreviated as:
/\bregexp/
Syntax with modifiers
new RegExp("\\bregexp", "g")
Or abbreviated as:
/\bregexp/g
Browser support
/\b/
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) | 字符串方法 match() |
text.search(pattern) | 字符串方法 search() |
pattern.exec(text) | RexExp 方法 exec() |
pattern.test(text) | RexExp Method test() |
- Previous Page \S
- Next Page \B
- Go to the Previous Level JavaScript RegExp Reference Manual