如何匹配preg_match()中的重音字符?

时间:2022-04-09 20:13:39

I've read how accented characters might sometimes match [a-z]. What I'd like to know is how I could match a specific accented character. Obviously, preg_match('/[ñ]/', 'ñ') does not work.

我已经读过重音字符有时候如何匹配[a-z]。我想知道的是我如何匹配特定的重音字符。显然,preg_match('/ [ñ] /','ñ')不起作用。

2 个解决方案

#1


16  

Use the /u modifier. That will enable Unicode for the regexes. http://php.net/manual/en/reference.pcre.pattern.modifiers.php

使用/ u修饰符。这将为正则表达式启用Unicode。 http://php.net/manual/en/reference.pcre.pattern.modifiers.php

#2


4  

You can take their codes and match them like \xD0 - heximal sequences if accented symbols are not accepted

如果不接受重音符号,您可以将它们的代码与\ xD0 - 十六进制序列匹配

#1


16  

Use the /u modifier. That will enable Unicode for the regexes. http://php.net/manual/en/reference.pcre.pattern.modifiers.php

使用/ u修饰符。这将为正则表达式启用Unicode。 http://php.net/manual/en/reference.pcre.pattern.modifiers.php

#2


4  

You can take their codes and match them like \xD0 - heximal sequences if accented symbols are not accepted

如果不接受重音符号,您可以将它们的代码与\ xD0 - 十六进制序列匹配