我是Java的新手,并且一直在寻找解决方案。.也许我不是在寻找正确的术语。
我的目标:我有一个Java类,该类使用webdriver转到页面,执行搜索...并输出结果。输出结果具有带URL的纯文本。我只关心URL的返回。所以基本上,我想将输出像这样:
搜索结果1
http://www.somesite.com/blahblah
这个
是来自搜索结果的网站。
但是我想要的只是URL,我想转储其余的输出。我已经研究了“在Java中解析”,但没有找到我想要的东西。任何指针将不胜感激。
最佳答案
Pattern pattern = Pattern.compile("http://[^\\s]*");
Matcher matcher = pattern
.matcher("Search result 1 http://www.somesite.com/blahbl+ah1 this is a site from the search results.\nSearch result 1 http://www.somesite.com/blahblah2 this is a site from the search results.");
for (int begin = 0; matcher.find(begin); begin = matcher.end())
{
System.out.println(matcher.group(0));
}