正则表达式匹配video标签视频地址

2023年07月3日

在获取video标签中的视频链接地址的时候,我们使用两个正则表达式就可以轻松作到了。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<video [^>]*src=['\"]([^'\"]+)[^>]*>
<video [^>]*src=['\"]([^'\"]+)[^>]*>
<video [^>]*src=['\"]([^'\"]+)[^>]*>

先使用上边的正则表达式获取到整个video标签内容,这个是避免匹配到其他标签内容。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
https(.*?){$md}
https(.*?){$md}
https(.*?){$md}
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
https.*\.(mp4|flv|ts)
https.*\.(mp4|flv|ts)
https.*\.(mp4|flv|ts)

 

上边这个是获取到真正的视频链接地址,$md是指视频后缀名

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
/*
* 正则获取网易视频的地址
* */
function wangyi_get_videourl($text, $md)
{
$str = $text;
$isMatched = preg_match("/<video [^>]*src=['\"]([^'\"]+)[^>]*>/", $str, $matches);
$ii = $matches[0];
$isMatched = preg_match("/https(.*?){$md}/", $ii, $matchesi);
$i = $matchesi[0];
return $i;
}
/* * 正则获取网易视频的地址 * */ function wangyi_get_videourl($text, $md) { $str = $text; $isMatched = preg_match("/<video [^>]*src=['\"]([^'\"]+)[^>]*>/", $str, $matches); $ii = $matches[0]; $isMatched = preg_match("/https(.*?){$md}/", $ii, $matchesi); $i = $matchesi[0]; return $i; }
/*
 * 正则获取网易视频的地址
 * */
function wangyi_get_videourl($text, $md)
{
    $str = $text;
    $isMatched = preg_match("/<video [^>]*src=['\"]([^'\"]+)[^>]*>/", $str, $matches);
    $ii = $matches[0];
    $isMatched = preg_match("/https(.*?){$md}/", $ii, $matchesi);
    $i = $matchesi[0];
    return $i;
}


sicnature ---------------------------------------------------------------------
I P 地 址: 3.143.244.80
区 域 位 置: 美国
系 统 信 息: 美国
Original content, please indicate the source:
同福客栈论坛 | 蟒蛇科普海南乡情论坛 | JiaYu Blog
sicnature ---------------------------------------------------------------------
Welcome to reprint. Please indicate the source https://myzhenai.com/post/4360.html

没有评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注