用正则表达式解析链接

时间:2018-03-31 19:56:36

标签: regex video asp.net-core-2.0

我有一个问题,我似乎无法弄清楚如何正确编写正则表达式。如何编写正则表达式,例如,如果我已经加载了一些文本,那么我感兴趣的部分是以.m3u或m3u8结尾的链接。例如,如果我在程序中指定此输入

输入 - player = new Player({"player-id":"1","autoplay":"false","fullscreen":"false","debug":"true","content-volume":"85","ad-volume":"30","ad-load-timeout":"15000","div-id":"videoPlayer","default-quality-index":0,"title":"\u0428\u043f\u0438\u043e\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u0435\u043d\u044f \u043a\u0438\u043d\u0443\u043b ","poster":"https://test/four/v1/video-file1/00/00/00/00/00/00/00/10/22/11/102211-480p.mp4/thumb-33000.jpg","content":{"mp4":[],"dash":"https://test/four/v1/video-file1/00/00/00/00/00/00/00/10/22/11/102211-,480,p.mp4.urlset/manifest.mpd","hls":"https://test/four/v1/video-file1/00/00/00/00/00/00/00/10/22/11/102211-,480,p.mp4.urlset/master.m3u8"},"about":"false","key":"4eeeb77181526bedc1025586d43a70fa","btn-play-pause":"true","btn-stop":"true","btn-fullscreen":"true","btn-prev-next":"false","btn-share":"true","btn-vk-share":"true","btn-twitter-share":"true","btn-facebook-share":"true","btn-google-share":"true","btn-linkedin-share":"true","quality":"true","volume":"true","timer":"true","timeline":"true","iframe-version":"true","max-hls-buffer-size":"10","time-from-cookie":"true","set-prerolls":["https://test/j/v.php?id=645"],"max-prerolls-impressions":1});

通过使用正则表达式,输出应为 -

https://test/four/v1/video-file1/00/00/00/00/00/00/00/10/22/11/102211-,480,p.mp4.urlset/master.m3u8

我尝试编写这个正则表达式,但它解析所有链接而不是我需要的链接。我只需要一个特定标签的链接 感谢您提前给出答案

1 个答案:

答案 0 :(得分:0)

我不明白为什么有那么多的downvotes,也许问题看起来完全不同了。

仅使用正则表达式,我在ASP.net中的解决方案是首先反转文本,然后查找" u3m"之间的所有内容。直到下一次出现" ptth"。

玩它:http://refiddle.com/nwvu

m3u8或m3u的正则表达式:

(8u3m.+?ptth)|(u3m.+?ptth)

ASP字符串反转(来自https://forums.asp.net/t/1841367.aspx?Reverse+String+in+asp+net):

string input = TextBox1.Text;
char[] inputarray = input.ToCharArray();
Array.Reverse(inputarray);
string output = new string(inputarray);