正则表达式匹配字母字符 [英] Regex matching letter characters

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

问题描述

我有这个正则表达式:

if (cadena.matches("^[a-zA-Z ]+$")) return true;

它接受从A到Z的小写和大写形式.也接受空格.

It's accepting from A to Z as lowercase and uppercase. Also accepting spaces.

但这仅适用于英语.例如,在加泰罗尼亚语中,我们有ç"字符.另外,我们还有带有'á'或'à'等字符.

But this is working just for english. For instance, in Catalan we've the 'ç' character. Also we've characters with 'á', or 'à', etc.

有一些Google,但我找不到任何方法.

Did some google and I couldn't find any way to do this.

我发现我可以过滤UTF-8,但这会接受不是真正字母的字符.

I found out that I can filter for UTF-8 but this would accept characters that are not really a letter.

我该如何实现?

推荐答案

使用此正则表达式:

[\p{L}\s]+

\ p {L} 表示任何Unicode字母.

\p{L} means any Unicode letter.

fiddle.re演示.

这篇关于正则表达式匹配字母字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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