我无法弄清楚如何编写一个正则表达式来查找以https://
开头并以.m3u8
我设法写了一个正则表达式,突出显示包含.m3u8
标记的字符串的特定部分
^(.*?(\m3u8\b)[^$]*)$
但我需要编写一个突出显示整个字符串的表达式。
还添加了示例文本
INPUT
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
注意:还有两个其他HTTP链接
https://test/four/v1/video-
file1/00/00/00/00/00/00/00/10/22/11/102211-,480,p.mp4.urlset/manifest.mpd
和
https://test/four/v1/video-file1/00/00/00/00/00/00/00/10/22/11/102211-480p.mp4/thumb-33000.jpg
它们不能被正则表达式突出显示,因为它们以http开头但不以.m3u8结尾
答案 0 :(得分:3)
你可以尝试:
https:\/\/[^"]+?\.m3u8
由于您所需的字符串不包含双引号"
,
[^"]+?
是一个非贪婪(懒惰)正则表达式,它匹配https://
和.m3u8
之间的"
请注意我在?
之后使用[^"]+
的方式,以便它也与其他任何链接都不匹配。
此外,\.
匹配一个句号,而.
只匹配任何字符。
答案 1 :(得分:0)
这个怎么样:
https:\/\/.*\.m3u8
寻找:
这应该突出显示完整的字符串。