简体   繁体   English

JavaScript测试RegExp函数非拉丁字符的bug

[英]JavaScript Test RegExp function non-latin characters bug

Well, I have noticed this during using console. 好吧,我在使用控制台时注意到了这一点。

> var a = new RegExp('\\b' + "абв" + '\\b', "gim");
> a.test("абв");
false

> var b = new RegExp("абв", "gim");
> b.test("абв");
true

And then with latin characters: 然后使用拉丁字符:

> var c = new RegExp('\\b' + "abc" + '\\b', "gim");
> c.test("abc");
true

I would glad to read your suggestions about fixing this. 我很高兴阅读您关于解决此问题的建议。

\\b refers only to word boundaries in an ASCII perception. \\b仅指ASCII感知中的单词边界。 You can create DIY boundaries. 您可以创建DIY边界。 Also if you already know the pattern will remain constant, use a regular expression literal as follows: 另外,如果您已经知道模式将保持不变,请使用正则表达式文字,如下所示:

/(^| )абв( |$)/.test("абв"); // true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM