我想在我拥有的内容中检索以“http”开头并以“.jpg”结尾的文本。 我现在所做的是:
public void captureURL(String content){
for(int i = 0; i < content.length() ; i++){
String test = content.substring(i);
if(test.startsWith("http://") && test.endsWith(".jpg")){
}
}
}
大图是:我使用 Asynctask 获取页面内容,然后搜索图像 URL。并将其保存在一些变量中。
最佳答案
你可以在这里使用正则表达式:
Pattern p = Pattern.compile("http\\://.+?\\.jpg");
Matcher m = p.matcher(content);
while (m.find())
{
System.out.println(content.substring(m.start(), m.end()));
}
关于java - 在更大的文本中检索某些文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6736767/