简体   繁体   English

Java 正则表达式名称(带空格和特殊字符)

[英]Java Regex names (with spaces and special characters)

I am building a program for a French soccer federation.我正在为法国足球联合会构建一个程序。

The names should be able to consist of "letters, spaces, ', - , è and é".名称应该能够由“字母、空格、'、-、è 和 é”组成。

But I am having trouble finding a good regex for this?但是我很难为此找到一个好的正则表达式?

Well, if there is no other rules for names, this piece of code should work:好吧,如果名称没有其他规则,这段代码应该可以工作:

String name = "namé";
Pattern pattern = Pattern.compile("[A-Za-z'èé\\s\\-]*");
Matcher matcher = pattern.matcher(name);
System.out.println(matcher.matches());

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

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