我不知道如何编写一个正则表达式来查找以 例如 开头 https://并以 结尾的特定字符串.m3u8
.m3u8我设法编写了一个正则表达式,突出显示包含标签的字符串的特定部分
^(.*?(\m3u8\b)[^$]*)$
Run Code Online (Sandbox Code Playgroud)
但我需要编写一个突出显示整个字符串的表达式。
还添加了示例文本
输入
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});
Run Code Online (Sandbox Code Playgroud)
输出:
https://test/four/v1/video-
file1/00/00/00/00/00/00/00/10/22/11/102211-,480,p.mp4.urlset/master.m3u8
Run Code Online (Sandbox Code Playgroud)
注意:还有另外两个 HTTP 链接
https://test/four/v1/video-
file1/00/00/00/00/00/00/00/10/22/11/102211-,480,p.mp4.urlset/manifest.mpd
Run Code Online (Sandbox Code Playgroud)
和,
https://test/four/v1/video-file1/00/00/00/00/00/00/00/10/22/11/102211-480p.mp4/thumb-33000.jpg
Run Code Online (Sandbox Code Playgroud)
它们不能通过正则表达式突出显示,因为它们以 http 开头但不以 .m3u8 结尾
你可以尝试:
https:\/\/[^"]+?\.m3u8
Run Code Online (Sandbox Code Playgroud)
由于您所需的字符串不包含双引号",
[^"]+?是一种非贪婪(惰性)正则表达式,它匹配 和 之间的一个或多个字符https://,而.m3u8这些字符不是"
并且请注意我如何使用?after [^"]+,以便它也不会与任何其他链接匹配。
此外,\.匹配句号,而只是.匹配任何字符。