相关疑难解决方法(0)

使用正则表达式检查字符串是否至少有两个数字

在深入研究堆栈溢出后,我发现了一些代码来检查字符串是否为字母数字且超过 8 个字符。它工作得很好。现在,如果它包含至少 2 个数字,我该如何让它返回 true?我想我必须在\d{2}某处添加。

String pattern = "^[a-zA-Z0-9]*$";

if (s.matches(pattern) && s.length() >= 8){
    return true;
}
return false;
Run Code Online (Sandbox Code Playgroud)

java regex

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

java ×1

regex ×1