gpt4 book ai didi

正则表达式开始于结束于

转载 作者:行者123 更新时间:2023-12-02 15:00:58 25 4
gpt4 key购买 nike

我不知道如何编写一个正则表达式来查找以 https:// 开头并以 .m3u8 结尾的特定字符串

我设法编写了一个正则表达式来突出显示包含 .m3u8 标记的字符串的特定部分

^(.*?(\m3u8\b)[^$]*)$

但我需要编写一个突出显示整个字符串的表达式。

enter image description here

也添加了示例文本

输入

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 结尾

最佳答案

你可以试试:

https:\/\/[^"]+?\.m3u8

As shown here

解释-

因为你想要的字符串不包含双引号 ",

[^"]+? 是一种非贪婪(惰性)正则表达式,它匹配 https:// 之间的一个或多个字符。 m3u8 不是 "

请注意我是如何在 [^"]+ 之后使用 ? 的,这样它也不会匹配任何其他链接。

另外,\. 匹配句号,而 . 会匹配任何字符。

关于正则表达式开始于结束于,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49595667/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com