[英]regex for a string only contains small letters
Hi I am trying to find a regEx which only accepts lower case letters nothing else, 嗨,我正在尝试找到一个仅接受小写字母的regEx,
I tired few options nothing worked, Can some one please guide me : 我厌倦了很少的选择,但没有任何效果,可以请一个指导我:
here are the expressions I tried : 这是我尝试过的表达式:
(?=.*[a-z])--> this is not working if we have "aaaAA"
[a-z]+^[A-Z]
^[A-Z]+[a-z]+^[A-Z]
Please help me. 请帮我。
Did you try just [az]+ 您是否尝试过[az] +
See example here: https://regex101.com/r/wCdBue/1 在此处查看示例: https : //regex101.com/r/wCdBue/1
If you want to check if whole line / text contains only lowercase letter you should wrap your regex with ^$ like this: ^[az]+$ 如果要检查整行/文本是否仅包含小写字母,则应使用^ $包裹正则表达式,如下所示:^ [az] + $
Example: https://regex101.com/r/T0DHY4/1 示例: https : //regex101.com/r/T0DHY4/1
Your solution is nearly correct. 您的解决方案几乎是正确的。 The regex must say "[az]+"—include a quantifier, which means that you are not matching a single character, but one or more lowercase characters.
正则表达式必须说“ [az] +” —包括一个量词,这意味着您不匹配单个字符,而是一个或多个小写字符。
String regex = "[az]+"; 字符串正则表达式=“ [az] +”;
Here is a quantifier regex link. 这是一个量词正则表达式链接。 http://docs.oracle.com/javase/tutorial/essential/regex/quant.html
http://docs.oracle.com/javase/tutorial/essential/regex/quant.html
It's working for me like this: 它对我来说是这样的:
String line = "aaaA";
System.out.println(line.matches("^[a-z]+$")); //false
line = "aaaa";
System.out.println(line.matches("^[a-z]+$")); //true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.