如何将重音符号与PHP preg匹配? [英] How do I match accented characters with PHP preg?
本文介绍了如何将重音符号与PHP preg匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想给我的用户一个选项,它不仅可以填写字母和数字,而且可以填写á",é"等特殊"字母.但是,我不希望他们能够使用!","@",%"等符号.
I’d like to give my users the option to not only fill in letters and numbers, but also "special" letters like the "á", "é", etc. However, I do not want them to be able to use symbols like "!", "@", "%", etc.
是否可以编写正则表达式来完成此任务? (最好不指定每个特殊字母.)
Is there a way to write a regex to accomplish this? (Preferably without specifying each special letter.)
现在我有
$reg = '/^[\w\-]*$/';
推荐答案
您可以使用 Unicode字符属性描述字符:
/^[\p{L}-]*$/u
\p{L}
描述Unicode字母字符的类别.
\p{L}
describes the class of Unicode letter characters.
这篇关于如何将重音符号与PHP preg匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文