JavaScript 中的正则表达式修饰符/u? [英] Regex modifier /u in JavaScript?

查看:99
本文介绍了JavaScript 中的正则表达式修饰符/u?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我为我的 PHP 代码创建了一个正则表达式,它只允许使用字母(包括特殊字符和空格),但现在我在将它(?)转换为与 JavaScript 兼容的正则表达式时遇到了问题,这里是: /^[\s\p{L}]+$/u, 问题在于正则表达式模式末尾的 /u 修饰符,因为 JavaScript 没有'不允许这样的标志.

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.

我怎样才能重写它,让它也能在 JavaScript 中工作?

How can I rewrite this, so it will work in the JavaScript as well?

是否有一些东西只允许波兰语字符:ŁĄ、ŚĆ、...

Is there something to allow only Polish characters: Ł, Ą, Ś, Ć, ...

推荐答案

/u 修饰符用于支持 unicode.ES2015 中的 JavaScript 中添加了对它的支持.

The /u modifier is for unicode support. Support for it was added to JavaScript in ES2015.

阅读http://stackoverflow.com/questions/280712/javascript-unicode以了解更多信息使用 JavaScript 在正则表达式中使用 unicode.

Read http://stackoverflow.com/questions/280712/javascript-unicode to learn more information about unicode in regex with JavaScript.

Ą \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]

这篇关于JavaScript 中的正则表达式修饰符/u?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆