public static void main(String[] args) {
String str = "(11)220219(17)230813(10)0122010313(21)2222030178";
String regex = "(\\([^\\)]*\\))";
List<String> list = new ArrayList<>();
list = getSubUtil(str, regex);
System.out.println(list);
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i));
if (i == (list.size() - 1)) {
System.out.println(str.substring(str.indexOf(list.get(i))+4));
} else {
System.out.println(str.substring(str.indexOf(list.get(i)) + 4, str.lastIndexOf(list.get(i + 1))));
}
}
}
/**
* 正则表达式匹配两个指定字符串中间的内容
*
* @param soap
* @return
*/
public static List<String> getSubUtil(String soap, String rgex) {
List<String> list = new ArrayList<String>();
Pattern pattern = Pattern.compile(rgex);// 匹配的模式
Matcher m = pattern.matcher(soap);
while (m.find()) {
int i = 1;
list.add(m.group(i));
i++;
}
return list;
}
?
|