1. 程式人生 > >如何用正則表示式獲得頁面中的指定資料?

如何用正則表示式獲得頁面中的指定資料?

我想得到一個table裡的每一行資料,格式如下:
<tr>
<td align='center' class='orang'>07098</td>
<td width='35' align='center' class='yellow'>3</td>
<td width='26' align='center' class='yellow'>7</td>
</tr>

於是我寫了這個程式,用來提取以<tr>開頭,</tr>結尾的內容
String regEx=".+(<tr>.+</tr>).+";
Pattern p=Pattern.compile(regEx,Pattern.DOTALL);
Matcher m=p.matcher(string); //string為頁面的HTML程式碼
while(m.find())
{
System.out.println(m.group(1));
}
但每次都只能得到表格的最後一行,這是為什麼啊?