第1个回答 2016-05-10
import java.util.regex.*;
public class Egg {
public static void main(String[] args) {
String reg = "(?<=[\\(\\)\\+\\-\\*\\/])[^\\(\\)\\+\\-\\*\\/]+(?=[\\(\\)\\+\\-\\*\\/])";
String str = "(单价*(数量1+数量11))/2";
String[] arr = {
"13", "33", "23"
};
Pattern p = Pattern.compile(reg);
Matcher m = p.matcher(str);
int i = 0;
while (m.find()) {
str = str.replaceFirst(m.group(), arr[i++]);
}
System.out.println(str);
}
}