java - 检查字符串中除特殊符号外的所有字符是否均为大写

标签 java regex

这是我第一次使用Java 的Pattern 类,因为我想检查一个字符串是否为大写。 “.”等特殊符号和“,”应被视为大写。以下是预期结果:

"test,." should return false //because it has a lowercase character
"TEST,." should return true //because all are uppercase and the special characters
"test" should return false //because it has a lowercase character
"TEST" should return true //because all are uppercase
"teST" should return false //because it has a lowercase character

我尝试使用 apache 的 StringUtils 但它不能这样工作..

最佳答案

您可以检查:

if (str.toUpperCase().equals(str)) {..}

关于java - 检查字符串中除特殊符号外的所有字符是否均为大写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20145591/

相关文章:

Java Applet 空指针异常

java - 在字符串中查找数字字符串并计数

python - 使用 python 正则表达式提取子字符串

php - preg_match 和关键字中的特殊字符不起作用

java - 警报对话框图标不会设置

java - 如何将 View 更改为 JTree?

java - JTable : Adding one to a JPanel, 并且它不显示自身

带有转义斜杠的 JavaScript 正则表达式不会替换

regex - 仅将文件的基本名称(不带扩展名的文件)与正则表达式匹配

python - Python 中捕获组的字符串操作