这是我需要匹配的请求的示例,我已将其存储为文本:
[{"id":"896","name":"TinyAuras","author_id":"654","author":"Kurisu</span></strong></span></a>","githubFolder":"https://github.com/xKurisu/TinyAuras/blob/master/TinyAuras.csproj","count":9,"countByChampion":{"":9,"total":9},"description":"(Beta) Aura/Buff/Debuff Tracker","udate":"1451971516","createdDays":375,"image":"https://cdn.joduska.me/forum/uploads/assemblydb/image-default.jpg","strudate":"2016-07-22 19:40","champions":null,"forum_link":"165574","assembly_compiles":true,"voted":false,"voted_champions":[]},
我想选择链接到这里(基本上是 github 文件夹,而不是实际的 csproj)。
我有一个包含数千个链接的文件,我正在尝试提取所有这些链接并将它们放入一个文本文件中。
这是目前为止我对 perl 正则表达式的了解:
(?<=githubFolder":").*(?=\/.+\.csproj")
但最终在第一场比赛后选择的比我需要的多。有什么建议吗?
问题是,我希望一切都在 this.csproj 之前。
所以在我的例子中我想提取: https://github.com/xKurisu/TinyAuras/blob/master/
最佳答案
这个正则表达式:
"githubFolder":"([^"]*/)[^"/]*"
选择:
https://github.com/xKurisu/TinyAuras/blob/master/
在你的例子中。
但是,正如 Jim D. 的回答所建议的那样,使用实际的 json 解析器可能会更好,这样您就不必担心空格和特殊字符。
关于正则表达式匹配两个分隔符之间的文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41648289/