Java 中仅允许两个或多个连字符的正则表达式。
最佳答案
是这样的:
String regexp = "--+";
使用方法如下:
Pattern p = Pattern.compile(regexpr);
System.out.println(p.matcher("fsdfsa").matches()); //false
System.out.println(p.matcher("-").matches()); //false
System.out.println(p.matcher("--").matches()); //true
System.out.println(p.matcher("-----").matches()); //true
关于java - java中只允许两个或多个连字符的正则表达式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13393331/