我编写了一个正则表达式来检查以下语句的验证
String pattern= "^how many [r|R]upees is (([A-Za-z\\s])+)\\?$";
String statment1 = "HOW MANY RUPEES IS RED BLUE GOLD ?"; // all caps
String statment2 = "how many Rupees is red blue Gold?";
System.out.println(statment1.matches(pattern));
System.out.println(statment2.matches(pattern));
输出
false
true
如果声明所有内容是否在大写下
,如何验证答案 0 :(得分:4)
只需在模式中添加(?i)
不区分大小写的修饰符。
String pattern = "(?i)^how many rupees is ([a-z\\s]+)\\?$";
答案 1 :(得分:0)
您可以尝试使用StringUtils isAllUpperCase
在没有正则表达式的情况下执行此操作检查CharSequence是否仅包含大写字符。
!StringUtils.isAllUpperCase("HOW MANY RUPEES IS RED BLUE GOLD ?") = false
!StringUtils.isAllUpperCase("how many Rupees is red blue gold?") = true