自认为高手的进来指点下

来源:百度知道 编辑:UC知道 时间:2024/09/20 08:43:42
String s="<p><img height="150" src="http://www.31home.cn/blog/blogManager/userPic/20080614140855.jpg" width="140" alt="" /></p>
<p>
<li>昵称:梦幻人生<img height="1118" alt="" width="1470" src="/UserFiles/Image/1215760724796.jpg" /></li>
</p>"我要把s里所有width得值取出来存放在一个数组里,即:Sting[] ss={140,1470}请问怎么做?

public static void main(String[] args) {
String s = "<p><img height=\"150\" src=\"http://www.31home.cn/blog/blogManager/userPic/20080614140855.jpg\" width=\"140\" alt=\"\" /></p><p><li>昵称:梦幻人生<img height=\"1118\" alt=\"\" width=\"1470\" src=\"/UserFiles/Image/1215760724796.jpg\" /></li></p>";
String regex = "width=\"[0-9]{0,}\"";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(s);
List<String> ss = new ArrayList<String>();
while (m.find()) {
int start = m.start();
int end = m.end();
String temp = s.substring(start + 7, end - 1);
ss.add(temp);