-4

我正在开发一个带有超链接的项目。我需要从 Java 中的字符串解析所有链接,但只有http://rapidshare.com链接。

所有解析的链接都应该填充到一个数组中。我的代码如下所示:

Matcher mat = Pattern.compile("(\"(.*?)\"|([^,]+)),?").matcher(html);

但它仍然得到其他单词括号和链接。我怎样才能得到这个工作?

quellcode 更新

Matcher mat = Pattern.compile("/href=\\\"(http://(www\\.)?rapidshare.com/.+)\\\"/").matcher(html);

while (mat.find()) {                        
    result.add(mat.group(2) == null ? mat.group(3) : mat.group(2));                 
}
4

1 回答 1

0

I am using this javascript regexp in my firefox add-on in production:

(?:h..ps?://)?(?:www\.)?rapidshare\.com/files/([0-9]+)/([^\s<"/]{1,500})/?

The popular JDownloader Java open source software is using this:

//    Copyright (C) 2008  JD-Team support@jdownloader.org
"http://[\\w\\.]*?rapidshare\\.com/files/\\d+/?(.*?)($|\\?)"

These two regular expressions are specifically for file links. They require a file name because the API requires a file name.

于 2012-04-05T12:57:48.183 回答