JavaScript RegExp \B Metacharacter

The RegExp \B Metacharacter in JavaScript is used to find a match that is not present at the beginning or end of a word. If a match is found it returns the word else it returns NULL.
Syntax:
/\B/
or
new RegExp("\\B")
Syntax with modifiers:
/\B/g
or
new RegExp("\\B", "g")
Example 1: This example matches the word “for” which is not present at the beginning or end of the word.
Javascript
| functiongeek() {    let str1 = "zambiatek@_123_$";    let regex4 = /\Bfor/gi;    let match4 = str1.match(regex4);    console.log("Found "+ match4.length        + " match: "+ match4);}geek(); | 
Found 1 match: for
Example 2: This example matches the word “Geeky” and replaces it with “GEEKY”.
Javascript
| functiongeek() {    let str1 = "123geeky456";    let regex4 = newRegExp("\\Bgeeky", "gi");    let replace = "GEEKY";    let match4 = str1.replace(regex4, replace);    console.log(" New string: "+ match4);}geek(); | 
New string: 123GEEKY456
Supported Browsers: The browsers supported by RegExp \B Metacharacter are listed below:
- Chrome
- Safari
- Firefox
- Opera
- Edge
We have a complete list of Javascript RegExp expressions, to check those please go through this JavaScript RegExp Complete Reference article.
We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.
 
				 
					


