\B is a non-word-boundary assertion. It matches a zero-width position where \b does not match — usually between two word characters (inside a token) or between two non-word characters.
Remember
\b → word boundary (word ↔ non-word, or string edge)
\B → NOT a word boundary (inverse of \b)
zero-width — matches a position, not a character
/\Bcat\B/.test("scatter") → true (cat inside a word)
/\Bcat\B/.test("a cat") → false (cat is a whole word)
/\bcat\b/.test("a cat") → true
Treat \B as a position check — place it where you need “still inside the same kind of characters.”
Decide whether you want a whole word (\b) or something embedded (\B).
Put \B before and/or after the text that must sit inside a larger token.
Remember it consumes no characters — only the surrounding pattern advances.
Combine with lookaheads for jobs like camelCase splits: \B(?=[A-Z]).
Piece
Required?
Role
\B in the pattern
Yes
Assert “this position is not a word boundary”
Surrounding text
Usually
What you actually want to find (e.g. cat)
Second \B
Optional
Require non-boundary on the other side too
Lookahead
Optional
e.g. (?=[A-Z]) for camelCase cuts
Pseudocode
Pseudocode
at position p in the string:
left = char before p (or "edge")
right = char after p (or "edge")
isBoundary =
(left is word) XOR (right is word)
// edges count as non-word
if pattern has \b:
accept only when isBoundary is true
if pattern has \B:
accept only when isBoundary is false
// neither \b nor \B consumes a character
Reference
Cheat Sheet
Keep these facts handy when matching inside tokens.
Topic
Detail
Type
Zero-width assertion (not a character)
Meaning
Position where \b fails
Typical hit
Between two \w chars (inside a word)
Also hits
Between two \W chars (e.g. inside "!!")
Embedded text
/\Bcat\B/
camelCase split
str.split(/\B(?=[A-Z])/)
Standard
ES3+ (universal)
Try it
Live Preview
Compare \B and \b on short sample strings.
Browser demo of the RegExp \B non-word-boundary assertion — same ideas as the examples below.
Result
text = "scatter"
/\Bcat\B/.test(text)
→ true
/* "cat" sits between letters — no word boundary */
Code
JavaScript Examples
Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.
Example 1 — Match Embedded cat
Return true when cat appears inside a longer word, not as a standalone token.
Position between letters. Lowercase then uppercase are both \w, so the spot between them is \B.
Lookahead.(?=[A-Z]) splits only when the next character is uppercase.
Clean camelCase.getUserAccountId becomes four parts.
Acronym caveat. Consecutive capitals each trigger a split — see Edge Cases.
Edge Cases & Pitfalls
Check these before relying on \B in real projects.
zero-width
\B never consumes a character
It only asserts a position. Pair it with real pattern text (or a lookahead) or it will not “select” anything useful alone.
edges
Word edges are boundaries
\Bcat\B fails on "cat", "catfish", and "bobcat" because at least one side sits on a word edge.
acronym
camelCase + acronyms
/\B(?=[A-Z])/ splits before every capital, so "parseJSON" becomes ["parse","J","S","O","N"]. Use a richer pattern for acronyms.
digits
\B\d+\B is not “digits between letters”
It can also match an interior digit inside "456" (the "5"). Prefer lookarounds like (?<=[A-Za-z])\d+(?=[A-Za-z]) when you mean letters on both sides.
Compatibility
Browser & Runtime Support
The \B non-word-boundary assertion is core regex syntax (ES3+) and works everywhere JavaScript runs.
✓ Baseline · ES3+
RegExp \B
Supported in every modern and legacy browser, plus all Node.js versions. No polyfill required.
100%Universal support
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 to use in any JavaScript environment. Lookbehind patterns for stricter “between letters” checks need modern engines (ES2018+).
Analysis
Performance Notes
Approach
Cost
Best for
/\B…\B/
O(n)
Embedded substring checks
/\b…\b/
O(n)
Whole-word matching
split(/\B(?=[A-Z])/)
O(n)
Simple camelCase splits
Boundary assertions are cheap position checks. Prefer \b for whole words and \B when you intentionally want matches inside tokens.
Remember
Key Takeaways
Role:\B matches positions that are not word boundaries.
Opposite of \b: whole-word edges vs insides of tokens.
Zero-width: asserts a position; it does not consume characters.
Practical: embedded search with \B…\B, camelCase with \B(?=[A-Z]).
One line:\B means “not a word edge” — use it to match inside tokens; use \b for whole words.
Frequently Asked Questions
\B is a non-word-boundary assertion. 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 a word character meets a non-word character, or the string edges). \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), or to split camelCase at uppercase letters with \B(?=[A-Z]).
No. Standalone cat has word boundaries on both sides. \Bcat\B requires non-boundaries on both sides, so it matches inside words like scatter or bobcatx, not a lone cat.
Non-word boundaries are core regex syntax since ES3. \B works in every browser and Node.js version.