JavaScript RegExp \BMetacharacter
JavaScript RegExp Object
Definition and Usage
The \B metacharacter matches a non-word boundary. The types of the previous and next characters at the matching position are the same: they must both be word characters, or both be non-word characters. The beginning and end of a string are treated as non-word characters.
If no match is found, it returns null.
Syntax
new RegExp(" \Bregexp")
Or a simpler way:
/\Bregexp/
Or a simpler way:
/\Bregexp/
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the \B metacharacter.
Example
Example
Perform a global search for "noob" in a string that is not at the beginning or end of a word:
var str="Visit Example";
var patt1=/\Bnoob/g;
Belowis markedThe text shows the positions where the expression obtained matches:
Visit Runoob
Try it yourself »
JavaScript RegExp Object Other Extensions