Latest web development tutorials

RegExp \ b metacharacter

RegExp Object Reference JavaScript RegExp Object

Definition and Usage

\ B metacharacter matches a word boundary.

\ B metacharacter is usually used to find the matching word located at the beginning or end.

grammar

new RegExp("\bregexp")

或者更简单方式:

/\bregexp/


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support \ b metacharacter


Examples

Examples

To the beginning or end of a string of words were "W3" global search:

var str="Visit W3CSchool";
var patt1=/\bW3/g;

The marked text below shows where the expression gets a match

Visit W3 Cschool

try it"


RegExp Object Reference JavaScript RegExp Object