2个回答
展开全部
public class MatchesTest {
public static void main(String[] args) {
String regex = "([\\d]{1,}|[\\d]+[-][\\d]+)";//1或者2,规则
String[] str = { "1", "13", "1-2", "11-22", "33--22", "10-", "-10", "a4", "b-10","-A","A-D" };
for (String s : str) {
sop(s, regex);
}
}
private static void sop(String str, String regex) {
String src = str.matches(regex) ? "合法" : "非法";
System.out.println(str + ":\t" + src);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询