1

我有以下 C# 代码:

string MyString = "<a href=\"magnet:?xt=urn:btih:7f3befa467c4cac0787286c87ea264a0606066f5&dn=some.file.name.zip&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80&tr=udp%3A%2F%2Ftracker.istole.it%3A6969&tr=udp%3A%2F%2Ftracker.ccc.de%3A80\" title=\"Download this torrent using magnet\">...</a>[Some unwanted stuff here]<a href=[Another]>";

MatchCollection MyMatches = Regex.Matches(MyString, "(?<URL>magnet:\\?.*?)(?:\"|')");           
foreach(Match MyMatch in MyMatches)
{
    MessageBox.Show(MyMatch.Groups["URL"].Value);
}

我的问题是:我怎样才能也放入&dn=some.file.name.zip一个名为的命名组<File>

4

1 回答 1

1
string MyString = "<a href=\"magnet:?xt=urn:btih:7f3befa467c4cac0787286c87ea264a0606066f5&dn=some.file.name.zip&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80&tr=udp%3A%2F%2Ftracker.istole.it%3A6969&tr=udp%3A%2F%2Ftracker.ccc.de%3A80\" title=\"Download this torrent using magnet\">...</a>[Some unwanted stuff here]<a href=[Another]>";

MatchCollection MyMatches = Regex.Matches(MyString, "(?<URL>magnet:\\?.*(&dn=(?<File>[^&]+)).*?)(?:\"|')");           
foreach(Match MyMatch in MyMatches)
{
    MessageBox.Show(MyMatch.Groups["URL"].Value);
    MessageBox.Show(MyMatch.Groups["File"].Value);
}
于 2012-11-27T07:21:54.220 回答