JavaScript RegExp \B meta character

Definition and usage

\B Meta characters do not match the beginning/end of the word.

Search pattern LO, not at the beginning of the word:

\BLO

Search pattern LO, not at the end of the word:

LO\B

Instance

Example 1

Find the first occurrence of "LO", not at the beginning of the word:

let text = "HELLO, LOOK AT YOU!";
let pattern = /\BLO/;

Try it yourself

Example 2

Find the first occurrence of "LO", not at the end of the word:

let text = "HELLO, LOOK AT YOU";
let pattern = /LO\B/;

Try it yourself

Syntax

new RegExp("\\Bregexp)

Or abbreviated as:

/\Bregexp/

Syntax with modifiers

new RegExp("\\Bregexp", "g")

Or abbreviated as:

/\Bregexp/g

Browser support

/\B/ It is an ECMAScript1 (ES1) feature.

All browsers fully support ES1 (JavaScript 1997):

Chrome IE Edge Firefox Safari Opera
Supported Supported Supported Supported Supported Supported

Regular expression search methods

In JavaScript, regular expression text search can be completed using different methods.

UsagePattern (pattern)As regular expressions, these are the most commonly used methods:

Example Description
text.match(pattern) String method match()
text.search(pattern) String method search()
pattern.exec(text) RexExp method exec()
pattern.test(text) RexExp Method test()