我编写了一个正则表达式来检查以下语句的有效性
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
如何验证语句是否全部都在大写字母范围内
最佳答案
只需在您的模式中添加 (?i)
不区分大小写的修饰符即可。
String pattern = "(?i)^how many rupees is ([a-z\\s]+)\\?$";
关于java - 使用正则表达式验证语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33035953/