旁观自己 善待朝夕|

猫老板的豆

园龄:9年4个月粉丝:52关注:0

js 截取字符串中url地址

function getUrl (str) {
    const reg = /(https?|http|ftp|file):\/\/[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]/g;
    str = str.match(reg);
    if (str && str.length > 0) {
        return str[0];
    }
    return null;
}

// 例:获取抖音链接中的url地址
getUrl ('8.79 XzT:/ 两年前的今天,山东舰入列,中国进入双航母时代首艘国产航母山东舰入列2周年  https://v.douyin.com/RKgyhQ5/ 复制此链接,打开Dou音搜索,直接觀kan視频');
// 'https://v.douyin.com/RKgyhQ5/'

本文作者:猫老板的豆

本文链接:https://www.cnblogs.com/bingcola/p/16499109.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   猫老板的豆  阅读(41)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 404 not found REOL
404 not found - REOL
00:00 / 00:00
An audio error has occurred.