第2个回答 2011-09-27
是不是就第一次出现“:”作为分割,后面的不管了?
你的字符串形式都和这个差不多的吧,给个不是太好的方法:
HashMap<String,String> hm = new HashMap<String, String>();
String s = "Date: Tue, 14 Sep 2010 13:51:13 GMT"+"Server: Apache"+"Cache-Control: max-age=86400";
Pattern p = Pattern.compile("(Date.*?)(Server.*?)(Cache-Control.*)");
Matcher m = p.matcher(s);
while(m.find()) {
String[] test = m.group(1).split(":",2);
hm.put(test[0], test[1]);
test = m.group(2).split(":",2);
hm.put(test[0], test[1]);
test = m.group(3).split(":",2);
hm.put(test[0], test[1]);
}本回答被网友采纳