The \B metacharacter matches a non-word-boundary position—a zero-width spot where \b would not match. Use it to find substrings embedded inside longer tokens, digits sandwiched between letters, or camelCase split points.
01
Non-boundary
\B
02
Zero-width
No characters consumed
03
Inverse
Opposite of \b
04
Inside word
\Bcat\B
05
Digits
\B\d+\B
06
camelCase
\B(?=[A-Z])
Fundamentals
Introduction
You already know that \b finds word edges. The uppercase form \B does the opposite: it matches positions that are not at a word boundary—typically the middle of a token where word characters sit on both sides.
Because \B is zero-width, it does not consume characters. It only checks whether the current position qualifies before the engine continues matching the rest of the pattern.
Concept
Understanding the \B Metacharacter
A word boundary (\b) sits where a word character ([A-Za-z0-9_]) meets a non-word character, or at the start/end of the string next to a word character. A non-word boundary (\B) matches everywhere else.
JavaScript
/\bcat\b/.test("a cat"); // true (whole word)
/\bcat\b/.test("scatter"); // false (inside word)
/\Bcat\B/.test("scatter"); // true (embedded)
/\Bcat\B/.test("a cat"); // false (has boundaries)
/\B/.test("ab"); // true (between a and b)
Think of \B as “not at a word edge.” It is essential when you need the inverse of whole-word matching.
💡
Beginner Tip
If \bcat\b finds standalone cat, then \Bcat\B finds cat buried inside a longer word like scatter or bobcatx.
Usage
How to Use \B in JavaScript
Use \B when you need to match inside tokens rather than at their edges:
Pair \B with lookahead ((?=[A-Z])), character classes, and quantifiers for precise inside-token patterns.
Foundation
📝 Syntax
JavaScript
\B // one non-word-boundary position
\Bword\B // word embedded inside a token
\B\d+\B // digits between word characters
\B(?=[A-Z]) // before uppercase in camelCase
\b // word boundary (inverse of \B)
Common patterns
/\Bcat\B/ — match cat only when embedded inside a word.
/\B\d+\B/g — extract digit runs sandwiched between letters.
/\B(?=[A-Z])/g — split camelCase identifiers.
/\Bthe\B/gi — find “the” inside words like “other” or “brother”.
Cheat Sheet
⚡ Quick Reference
Goal
Pattern
Non-boundary position
\B
Substring inside word
\Bword\B
Embedded digits
\B\d+\B
Split camelCase
/\B(?=[A-Z])/g
Whole word (opposite)
\bword\b
Inverse anchor
\b ↔ \B
Compare
📋 \B vs \b
Two inverse zero-width anchors for word edges and non-edges.
Non-boundary
\B
Inside tokens
Word boundary
\b
At word edges
Embedded
\Bcat\B
Inside word
Whole word
\bcat\b
Standalone
Hands-On
Examples Gallery
Open DevTools Console (F12) or use Try-it links. Examples contrast \b and \B, find embedded substrings, extract inline digits, and split camelCase.
📚 Getting Started
See how \B matches inside words where \b fails.
Example 1 — Test for Embedded cat
Return true when cat appears inside a longer word, not as a standalone token.
Between a lowercase and uppercase letter, both characters are word chars—so the position is a \B (non-boundary). The lookahead (?=[A-Z]) splits only before capitals.
Applications
🚀 Common Use Cases
Embedded substring search — find text inside longer tokens with \B...\B.
Inline ID extraction — pull digits embedded in SKUs with \B\d+\B.
camelCase parsing — split identifiers at \B(?=[A-Z]).
Inverse whole-word logic — exclude standalone matches when \b is too broad.
Token analysis — detect positions inside compound words for NLP-style processing.
Refactoring tools — rename variables without hitting partial matches at word edges.
Watch Out
Important Considerations
Zero-width only — \B matches positions, not characters. It adds no length to the result.
Inverse of \b — wherever \b succeeds, \B fails, and vice versa (at the same position).
Underscore counts — underscore is a word character, so a_b has \B between the letters and underscore.
Not a character class — do not confuse \B (non-boundary) with \W (non-word character).
Start/end edges — string start/end next to a word char is a \b position, not \B.
🧠 How \B Checks Positions
1
Reach position
The engine arrives at a zero-width point between characters (or at start/end).
Anchor
2
Test \b
Internally, \B succeeds when \b would fail at that spot.
Invert
3
Continue pattern
If \B passes, matching continues with the next token in the pattern.
Word characters are [A-Za-z0-9_] by default in JavaScript.
For whole-word replacement, prefer \bword\b; for inside-word matches, use \Bword\B.
Compatibility
Browser & Runtime Support
The \B non-word-boundary anchor is part of core JavaScript regular expression syntax.
✓ Baseline · ES3+
RegExp \B
Supported in every browser and Node.js version. \B is the standard inverse of the \b word-boundary anchor.
99%Universal syntax
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
\BExcellent
Bottom line: Safe everywhere. Use \B when you need positions that are not at word edges.
Wrap Up
Conclusion
The \B metacharacter matches non-word-boundary positions—the inverse of \b. It is zero-width, consumes no characters, and excels at finding substrings embedded inside tokens.
Use \Bword\B for inside-word matches, \B\d+\B for inline digits, and \B(?=[A-Z]) for camelCase splitting. Next, learn the \0 null character metacharacter.
Forget underscore is a word character in boundary checks
Assume \B works the same as negating \b in all regex flavors (verify in JS)
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about RegExp \B
Match positions that are not at word edges.
5
Core concepts
🔗01
Non-boundary
\B
Syntax
🚫02
Zero-width
No chars.
Anchor
📈03
\Bcat\B
Embedded.
Pattern
🔢04
\B\d+\B
Inline nums.
Extract
📚05
\b
Inverse.
Pair
❓ Frequently Asked Questions
\B is a non-word-boundary anchor. It matches a zero-width position where \b would NOT match—typically between two word characters inside the same token, or between two non-word characters.
No. Like \b, \B is a zero-width assertion. It checks a position between characters (or at the start/end) without consuming any text.
\b matches word boundaries (where word and non-word characters meet). \B is the inverse and matches positions that are not word boundaries—such as the middle of a word.
Use \B to find substrings embedded inside longer tokens (for example, cat inside scatter), digits sandwiched between letters, or to split camelCase at uppercase letters with \B(?=[A-Z]).
No. Standalone cat has word boundaries on both sides. \Bcat\B requires cat to be surrounded by word characters on both sides, so it matches inside words like scatter or bobcatx but not a cat by itself.
Non-word boundaries are core regex syntax since ES3. \B works in every browser and Node.js version.
Did you know?
JavaScript has four common zero-width anchors: ^ and $ for string start/end, plus \b and \B for word-boundary positions. None of them consume characters—they only test whether the current position qualifies.