JavaScript RegExp \B Metacharacter
Example
Find the first occurrence of "LO" where it is NOT at the beginning of a word:
var str = "HELLO, LOOK AT YOU!";
var patt1 = /\BLO/;
Try it Yourself »
Definition and Usage
The \B metacharacter is used to find a match, but where it is NOT at the beginning/end of a word.
Search for the pattern NOT at the beginning of a word like this:
\BLO
Search for the pattern NOT 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
Find the first occurrence of "LO" where it is NOT at the END of a word:
var str = "HELLO, LOOK AT YOU";
var patt1 = /LO\B/;
Try it Yourself »