JavaScript RegExp \b Metacharacter
Example
Do a search for "LO" at the beginning of a word in a string:
var str = "HELLO, LOOK AT YOU";
var patt1 = /\bLO/;
Try it Yourself »
Definition and Usage
The \b metacharacter is used to find a match at the beginning or end of a word.
Search for the pattern at the beginning of a word like this:
\bLO
Search for the pattern at the end of a word like this:
LO\b
If no match is found, it returns null.
Browser Support
Expression | |||||
---|---|---|---|---|---|
\b | Yes | Yes | Yes | Yes | Yes |
Syntax
new RegExp("\\bregexp")
or simply:
/\bregexp/
Syntax with modifiers
new RegExp("\\bregexp", "g")
or simply:
/\bregexp/g
More Examples
Example
Do a search for "LO" at the END of a word in a string:
var str = "HELLO, LOOK AT YOU";
var patt1 = /LO\b/;
Try it Yourself »