java 正则表达式 65个字母内只包含数字,空格,+号 三种的该如何写呢
{String x = "18749237 +322+2";
String regex = "[+ \d]{0,65}";
Boolean result = x.matches(regex);
if(result){
System.out.println("符合规则");
}else {
System.out.println("不符合规则");
}
}
[+ \d]{65}
^[a-zA-Z0-9+\s]+$
^[\d \+]{65}$
正则表达式,“65个字母内只包含数字,空格,+号 三种”匹配串:[\d+ ]{65}
String content = "1 22 +4 579653+643001 22 +4 579653+643001 22 +4 579653+64300+++22";
String str = new String("[\\d+ ]{65}");
boolean isMatch = Pattern.matches(str, content);
System.out.println("字符串是否符合要求: " + isMatch);
上面代码片段,,亲测可行,,有问题还可以追问
[\d \+]+
String patternStr = "[\d \+]+"; //java中反斜杠要转义
//测试字符串
String str = "7 8+4 +";
Matcher meq = Pattern.compile(patternStr).matcher(str);
if(meq.matches()){
System.out.println("~~~完全匹配~~");
}
^[\d\n+]{65}$
^[\d\n+]{65}$