没有数字 Java 正则表达式模式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1959467/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
No digits Java Regex Pattern
提问by Waseem
I want a regex pattern to check that the string doesn't contain any digits .
我想要一个正则表达式模式来检查字符串不包含任何数字。
For Illustration : I'm coding a Hospital System and I want from user to enter the name of the patient , Of course the name shouldn't contain any digits , how can I do this by Regex ?
举例说明:我正在编写一个医院系统,我希望用户输入患者的姓名,当然姓名不应包含任何数字,我如何通过 Regex 执行此操作?
采纳答案by MatrixFrog
\D
is a non-digit, and so then \D*
is any number of non-digits in a row. So your whole string should match \D*
.
\D
是非数字,因此\D*
是任意数量的非数字。所以你的整个字符串应该匹配\D*
.
回答by fastcodejava
Well names usually alphabetical, so this will be good : [a-b,A-Z, ,-]+
井名通常按字母顺序排列,所以这会很好: [a-b,A-Z, ,-]+
EDIT : [a-zA-Z- ',]+
编辑 : [a-zA-Z- ',]+