Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

RegExp \b metacharacter

JavaScript RegExp \b metacharacter

RegExp Object Reference JavaScript RegExp Object


Definition and Usage

The \b metacharacter matches a word boundary.

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

Syntax

new RegExp("\b

regexp

")

Or a simpler way:

/\b

regexp

/


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the \b metacharacter


Example

Example

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

var

str

=

"

Visit Runooob

"

;

var

patt1

=/\

bRun

/

g

;

The text marked below shows where the expression found matches.

Visit

Run

oob

Try it »


RegExp Object Reference JavaScript RegExp Object