展开全部
刚看了一下,有的回答只给思路,没具体做法。有的回答只是针对一种情况的。给你一32313133353236313431303231363533e58685e5aeb931333332626637个稍微通用点的吧,如果有问题再联系我。import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class StringAnalyze {
private Pattern p = Pattern.compile("\\([^)]*\\)");
private List result;
public void analyze(String content){
Matcher m = p.matcher(content);
if(m.find()){
String tmp = m.group();
tmp = tmp.substring(1, tmp.length() - 1);
String pre = content.substring(0, m.start());
String suf = content.substring(m.end());
String[] sp = tmp.split("\\|");
for(String s : sp){
analyze(pre + s + suf);
}
}else{
result.add(content);
}
}
public String[] getNeedStrings(String content){
result = new ArrayList();
analyze(content);
return result.toArray(new String[1]);
}
public static void main(String[] args) {
StringAnalyze sa = new StringAnalyze();
for(String s : sa.getNeedStrings("a1.asdf.(asfd1|fjdk):aa")){
System.out.println(s);
}
System.out.println("----------------------");
for(String s : sa.getNeedStrings("a1.asdf.(asfd1|fjdk):(aa|bb|cc)")){
System.out.println(s);
}
System.out.println("----------------------");
for(String s : sa.getNeedStrings("a1.asdf.(asfd1|fjdk):(aa|bb|cc):(ee|ff)")){
System.out.println(s);
}
}
}