开发者

Why does this PHP regex not match for accented characters?

I'm writing a quick PHP page, and I need to ignore any Strings with accented characters. I am using this preg_match() string on each word:

"[ÀÁÅÃÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ]"

(Quite a brute force method I know, but apparently [a-zA-Z] can match for accented characters)

But the functi开发者_Go百科on never seems to return true when it searches Strings with accented characters (Examples: "cheap…", "gustaría"...)

I haven't used Regex before, so please point out any stupid mistakes I'm making here!


PHP regexes need delimiters, like so:

preg_match('/[ÀÁÅÃÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ]/', "gustaría");

Note that it's also preferable to use single quotes for regex because the dollar sign could be mistaken by php as a variable.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜