正则表达式不匹配空格(正则表达式,判断string不能与空并且不能有空格)

本文目录
正则表达式,判断string不能与空并且不能有空格
var str =“fafafassssssfpa[fakfp99w32eflkfSDFSDDFAF++___“;
var reg = /\s/g;
if (reg.test(str)) {
alert(“存在空格“);
};
if(!str){
alert(“字符串为空“);
}
console.log(str);
希望能帮到你,有用就采纳!!
正则表达式,如何不匹配到空字符
import java.util.regex.*;
public class RegexTest {
private static String ONE = “49785790f0aba048e55a0289f377edb4“;
private static String PATTERN = “(com/7655/zh-cn/preview/)(\\w{“ + ONE.length() + “})(/preview)“;
public static void main(String args) {
String dist = null;
Pattern p = Pattern.compile(RegexTest.PATTERN);
String input =
“com/7655/zh-cn/preview/11111111111/preview“ +
“com/7655/zh-cn/preview/22222222222222222222222222222222222222/preview“ +
“com/7655/zh-cn/preview/49785790f0aba048e55a0289f377edb4/preview“;
Matcher m = p.matcher(input);
while(m.find()) {
String g = m.group();
// System.out.println(g);
dist = g;
}
System.out.println(dist);
}
}

更多文章:
majority of(the majority of 和 a majority of的区别以及用法例句)
2026年10月11日 07:40
another time(another time和other time的区别)
2026年10月11日 05:00







