我使用HttpClient的下載網站的源代碼,然後我想提取使用正則表達式的一些數據。不幸的是該網站編碼在ISO-8859-1,這似乎是造成問題。這裏的示例代碼下載網站:Android的正則表達式編碼
HttpGet query = new HttpGet(url);
HttpResponse queryResponse = httpClient.execute(query);
String queryText = EntityUtils.toString(queryResponse.getEntity()).replaceAll("\r", " ").replaceAll("\n", " ");
然後表達:
Pattern patter = Pattern.compile("<p class=\"qt\">(.*?)</p>");
Matcher matcher = pattern.matcher(queryText);
while (matcher.find()) // do something
的問題是,它缺少一些出現次數,當有特殊的ISO-8859-1字符。 (.*?)
似乎不匹配它們。這個問題的原因是什麼?我如何解決它?
整個「我想使用正則表達式」是第一個錯誤;你會考慮只使用類似[jsoup(http://jsoup.org/)或[tagsoup(http://ccil.org/~cowan/XML/tagsoup/)呢?否則,[這可能是你](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454)。 –