JavaScript RegExp \bMetacharacter

RegExp 对象参考手册JavaScript RegExp Object

Definition and Usage

The \b metacharacter matches word boundaries.

The \b metacharacter is usually used to find matches at the beginning or end of a word.

Syntax

new RegExp("\bregexp")

Or in a simpler way:

/\bregexp/


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the \b metacharacter


Example

Example

Perform a global search for "Run" at the beginning or end of words in a string:

var str="Visit Runooob"; var patt1=/\bRun/g;

BelowmarkedThe text shows where the expression gets matches

Visit Runoob

Try it yourself »


RegExp 对象参考手册JavaScript RegExp Object Other Extensions