RegExp \B Metacharacter (uppercase B) - Javascript RegExp

Javascript examples for RegExp:Metacharacter

Description

The \B metacharacter matches not at the beginning or end of a word.

If no match is found, it returns null.

The following code shows how to Do a global search for "book2s" NOT at the beginning or end of a word in a string:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p id="demo"></p>

<button onclick="myFunction()">Test</button>

<script>
function myFunction()//from  w  ww .ja va 2  s .c  o m
{
var str = "Visit java2s.com";
var patt1 = /\Bbook2s/g;
var result = str.match(patt1);
document.getElementById("demo").innerHTML=result;
}
</script>

</body>
</html>

Related Tutorials