我使用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)。 –