So the answer is just, that you can not use the JavaScript native mechanisms or any library which uses those mechanisms to match words the way you want to. As you already stated, \b matches words. Words must consists of word characters. And in JavaScript (and actually other regex implementations word characters are a-z, A-Z, 0-9 and _. But many other Languages just implement the \b metacharacter in a different way JavaScript does.
The answer "JavaScript does not support Unicode" is a bit to easy and in fact completely wrong. JavaScript just doesn't use unicode for the character classes. If JavaScript wouldn't support unicode you couldn't even use unicode Characters in String literals and of course this is possible in JavaScript.
According to the ECMA 262 Standard (ECMAScript) (Section 15.10.2.6):
[...]
The production Assertion :: \ b evaluates by returning an internal AssertionTester closure that takes a State
argument x and performs the following:
- Let e be x's endIndex.
- Call IsWordChar(e–1) and let a be the Boolean result.
- Call IsWordChar(e) and let b be the Boolean result.
- If a is true and b is false, return true.
- If a is false and b is true, return true.
- Return false.
[..]
The abstract operation IsWordChar takes an integer parameter e and performs the following:
- If e == –1 or e == InputLength, return false.
- Let c be the character Input[e].
- If c is one of the sixty-three characters below, return true.
a b c d e f g h i j k l m n o p q r s t u v w x y z
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
0 1 2 3 4 5 6 7 8 9 _
- Return false
This just shows, that the \b uses the Algorithm of "isWordChar" to check if what you try to match is actually a word. Int he definition of "isWordChar" you can see the exact definition of which characters will return true for "isWordChar".
In my Opinion this has absolutely nothing to do with the character set being used. It's neither ASCII nor UNICODE compilant here. It's just these 63 characters.
\b
to work according to the requirements of The Unicode Standard. It cannot be correctly implemented using only Unicode general categories, and even its approximation is mind-bending:(?:(?<=\w)(?!\w)|(?<!\w)(?=\w))
. You would have to replace\w
with[\pL\pM\p{Nd}\p{Nd}\p{Pc}]
wherever it occurs there, and you couldn’t — because Javascript cannot manage to do standard lookbehinds. So that plugin cannot solve this problem. – Mastoidectomy\b${word}\b
. – Aframe