简体   繁体   English

如何使用正则表达式从磁铁URI中获取名称?

[英]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.

相关问题 正则表达式将从磁铁链接中获得标题:“未终止的地址正则表达式” - Regex to get title from magnet link: “unterminated address regex” 有什么方法可以使用 RegEx 从 Flutter / Dart 中的磁链或复杂字符串获取大小信息(MB,GB)? - Is there is any way to get a size information (MB,GB) from a magnet link or a complex string in Flutter / Dart using RegEx? 我如何使用正则表达式摆脱这个“(”? - How do I get rid of this “(” using regex? 来自磁力链接的perl正则表达式匹配infohash - perl regex matching infohash from magnet link 如何在 C# 正则表达式中获取捕获组的名称? - How do I get the name of captured groups in a C# Regex? 如何使用Regex(知道变量名)从URL中提取数据? - How do I extract the data from the URL using Regex (Know the variable name)? 你如何获得正则表达式的组名? - How do you get the group name of a regex? 如何使用Java正则表达式从URI中提取UUID - How to extract the UUID's from the URI using Java regex 如何使用RegEx从JSON获取所有字符串值而不是Key? - How do I get all string values, not Keys, from a JSON using RegEx? 如何使用 substr/regex 函数验证过滤器并从 Oracle PLSQL 中的存储过程获取结果? - How do I validate the filters using substr/regex function and get results from stored procedure in Oracle PLSQL?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM