Latest web development tutorials

RegExp \ B metacharacter

RegExp Object Reference JavaScript RegExp Object

Definition and Usage

\ B metacharacter matches non-word boundary. On a matching location and type the next character is the same: that the word must be, or must be a non-word character. The beginning and end of the string is considered a non-word character.

If no match is found, it returns null.

grammar

new RegExp(" \Bregexp")

或者更简单方式:

/\Bregexp/


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support \ B metacharacter


Examples

Examples

String is not located in the beginning or end of a word "school" a global search:

var str="Visit W3Cschool";
var patt1=/\Bschool/g;

The marked text below shows where the expression gets a match:

Visit W3C School

try it"


RegExp Object Reference JavaScript RegExp Object