没有数字 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 01:48:31  来源:igfitidea点击:

No digits Java Regex Pattern

javaregex

提问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

\Dis 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 Fried Hoeben

Try: \D

试试:\D

See the JavaDoc for Pattern

请参阅模式的 JavaDoc

回答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- ',]+

回答by Arthur Thomas

\A\D*\Z

\A\D*\Z

a good regex cheatsheethere

这里有一个很好的正则表达式备忘单