题意:JavaScript 中的正则表达式修饰符 /u 是什么?
问题背景:
Recently I have created a regex, for my PHP code which allows only the letters (including special characters plus spaces), but now I'm having a problem with converting it (?) into the JavaScript compatible regex, here it is: /^[\s\p{L}]+$/u
, the problem is the /u
modifier at the end of the regex pattern, as the JavaScript doesn't allow such flag.
最近我为我的 PHP 代码创建了一个正则表达式,允许只有字母(包括特殊字符和空格),但现在我在将其转换为 JavaScript 兼容的正则表达式时遇到问题,下面是我的正则表达式:`/^[\s\p{L}]+$/u`,问题在于正则表达式模式末尾的 `/u` 修饰符,因为 JavaScript 不允许这样的标志。
How can I rewrite this, so it will work in the JavaScript as well?
我该如何重写这个,以便它也能在 JavaScript 中工作?
Is there something to allow only Polish characters: Ł
, Ą,
Ś
, Ć
, ...
![](/qrcode.jpg)
有没有什么方法可以只允许波兰字符:Ł、Ą、Ś、Ć 等?
问题解决:
The /u
modifier is for unicode support. Support for it was added to JavaScript in ES2015.
`/u` 修饰符用于支持 Unicode。JavaScript 在 ES2015 中添加了对它的支持。
Read http://stackoverflow.com/questions/280712/javascript-unicode to learn more information about unicode in regex with JavaScript.
请阅读 [http://stackoverflow.com/questions/280712/javascript-unicode](http://stackoverflow.com/questions/280712/javascript-unicode) 以获取有关 JavaScript 中正则表达式的 Unicode 详细信息。
Polish characters:
波兰字符:
Ą \u0104
Ć \u0106
Ę \u0118
Ł \u0141
Ń \u0143
Ó \u00D3
Ś \u015A
Ź \u0179
Ż \u017B
ą \u0105
ć \u0107
ę \u0119
ł \u0142
ń \u0144
ó \u00F3
ś \u015B
ź \u017A
ż \u017C
All special Polish characters:
所有特殊的波兰字符:
[\u0104\u0106\u0118\u0141\u0143\u00D3\u015A\u0179\u017B\u0105\u0107\u0119\u0142\u0144\u00F3\u015B\u017A\u017C]