3-7,9-10怎么用正则表达式拆分成3 4 5 6 7 9 10
1091011怎么拆分成1 9 10 11
第一个可以通过
String str = "3-7,9-10";//输入
Pattern p = Pattern.compile("([1-9][0-9]{0,}-[1-9][0-9]{0,})");
Matcher matcher = p.matcher(str);
while(matcher.find()) {
String group = matcher.group();
String[] strs = group.split("-");
int firstNum = Integer.parseInt(strs[0]);
int secondNum = Integer.parseInt(strs[1]);
for(;firstNum<=secondNum;firstNum++) {
System.out.println(firstNum); //结果
}
}
第二个规律不明显