简体   繁体   English

正则表达式无法允许撇号

[英]regex unable to allow apostrophe

I am experiencing a strange problem with a regular expression I have already used before. 我以前使用过的正则表达式遇到一个奇怪的问题。 The goal is to allow the user to enter his name, with letters, hyphen, and apostrophes if needed in a php form. 目的是允许用户以php形式输入他的名字,包括字母,连字符和撇号。 My regex is: 我的正则表达式是:

 "/^[\w\s'àáâãäåçèéêëìíîïðòóôõöùúûüýÿ-]+$/i"

But... everything is allowed but the apostrophe. 但是...除了撇号外,所有内容都允许。 Escaping it will not change. 转义不会改变。 Why? 为什么?

To deal with unicode characters, you can do: 要处理unicode字符,您可以执行以下操作:

/^[\pN\pL\pP\pZ]+$/

where: 哪里:

\pN  stands for any number
\pL  stands for any letter
\pP  stands for any punctuation
\pZ  stands for any space

It matches names like: 它匹配如下名称:

d'Alembert  
d’Alembert    (note the different apos from above)
Jean-François
O'Connors

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

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