android - 从频道 url 中提取 youtube 频道 ID - android
问题描述
示例网址: https: //www.youtube.com/channel/UCAoMPWcQKA_9Af5YhWdrZgw
我只需要 UCAOMPWcQKA_9Af5YhWdrZgw(频道 ID)
解决方案
Subhendu Mondal 的决定在这样的链接上崩溃。
// args after id
https://www.youtube.com/channel/UCAoMPWcQKA_9Af5YhWdrZgw?view_as=subscriber
//minus sign in id
https://www.youtube.com/channel/UCQ18THOcZ8nIP-A3ZCqqZwA
所以这是改进的决定,协议组也从匹配结果中删除
^(?:http|https):\/\/[a-zA-Z-]*\.{0,1}[a-zA-Z-]{3,}\.[a-z]{2,}\/channel\/([a-zA-Z0-9_\-]{3,24})
var str = "https://www.youtube.com/channel/UCAoMPWcQKA_9Af5YhWdrZgw";
var pattern = /^(?:(http|https):\/\/[a-zA-Z-]*\.{0,1}[a-zA-Z-]{3,}\.[a-z]{2,})\/channel\/([a-zA-Z0-9_]{3,})$/;
var match = str.match(pattern);
console.log(match[1]);
更新:
这是最短的方法:
youtube.com\/channel\/([^#\&\?]*).*
推荐阅读
- google-cloud-platform - 通过 Google SSO 登录时出现授权错误
- go - 如何使用 redigo 库使用 Blpop
- python - 在熊猫中获取多个列子集
- azure - 我需要哪些 vscode 扩展来运行这个 powershell 代码?
- cobol - cobol 中显示时十进制值变为 00
- python - python中的Selenium - 初始化驱动程序
- reactjs - 在部署 React 应用程序时,“没有'new'就不能调用类构造函数解析器”
- azure - 是否可以在本地运行 Azure 逻辑应用程序
- javascript - 使用 Babel 转译器时,在 iPad-Pro 中以横向模式显示时,图像会发生偏移
- python - 如何在 C++ 进程中将数据从 CPU 复制到 GPU,并在另一个 python 进程中运行 TF,同时指向复制的内存?