^1001-9dd12$ 这个正则表达式怎么调整为不包含0和100支持小数并用java进行测试
可以将100和0%排除掉,也就是修改为(?!100\.?0*%|^0\.?0*%|^100\.?0*%)([1-9]?\d(.\d{1,2})?%|100%)。以下是Java代码示例:
String regex = "(?!100\\.?0*%|^0\\.?0*%|^100\\.?0*%)([1-9]?\\d(\\.\\d{1,2})?%)";
String str = "50.5%, 100%, 0.0%, 0%, 101%, 50.55%";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(str);
while (matcher.find()) {
System.out.println(matcher.group());
}
输出结果为:
50.5%
50.55%
原文地址: https://www.cveoy.top/t/topic/7Td 著作权归作者所有。请勿转载和采集!