[英]How do I get the name from a magnet URI using regex?
How do I get the name of a torrent from a magnet link using regex? 如何使用正则表达式从磁力链接获取种子名称? The URI looks like this: URI如下所示:
magnet:?xt=urn:btih:1e4dae83371ba704d5d89e1828068ef0c4151e32&dn=Steam+OS+Official+Installer&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&tr=udp%3A%2F%2Fopen.demonii.com%3A1337
I thought &dn*&
would work but it gets it to the last &, when I only want the one after the dn. 我以为&dn*&
可以工作,但是到了最后一个&时(我只想要dn之后的那个)。
I want everything from '&dn=
to the next &
, but I can't get the pattern right, can anybody offer me some insight on the best way to do this and explain each part of the pattern? 我想要从'&dn=
到下一个&
,但我无法正确理解模式,有人可以为我提供一些最佳方法并解释模式的每个部分的见解吗? Thank you. 谢谢。
Use lazy matching (by adding ?
to the group construct): 使用延迟匹配 (通过在组构造中添加?
):
&dn=(.*?)&
Which simply means, a match will end on first &
, opposite to the default greedy matching when it will try to match as much as possible. 这只是意味着,匹配将在第一个&
结束,这与默认的贪婪匹配相反,它将尝试尽可能地匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.