<script src="xregexp.js"></script>
<script src="xregexp-unicode-base.js"></script>
<script>
var unicodeWord = XRegExp("^\\p{L}+$");
unicodeWord.test("Русский"); // true
unicodeWord.test("日本語"); // true
unicodeWord.test("العربية"); // true
</script>
<!-- \p{L} is included in the base script, but other categories, scripts,
and blocks require token packages -->
<script src="xregexp-unicode-scripts.js"></script>
<script>
XRegExp("^\\p{Katakana}+$").test("カタカナ"); // true
</script>
抽象操作 IsWordChar 接受一个整数参数 e,并执行以下操作:
在我看来,这与所使用的字符集完全无关。它既不符合ASCII也不符合UNICODE。只涉及这63个字符。
\b
正确地修正为符合Unicode标准要求的工作方式。它无法仅使用Unicode通用类别进行正确实现,即使是其近似值也令人费解:(?:(?<=\w)(?!\w)|(?<!\w)(?=\w))
。您必须在出现的每个位置上将\w
替换为[\pL\pM\p{Nd}\p{Nd}\p{Pc}]
,但您无法这样做——因为Javascript无法管理标准的向后查找。因此,该插件无法解决此问题。 - tchrist