从频道url提取youtube频道id-android
示例URL:从频道url提取youtube频道id-android,android,regex,youtube,youtube-channels,Android,Regex,Youtube,Youtube Channels,示例URL: 我只需要将字符串解析为URI: Uri uri = Uri.parse("https://www.youtube.com/channel/UCAoMPWcQKA_9Af5YhWdrZgw") String id = uri.lastPathSegment() //UCAoMPWcQKA_9Af5YhWdrZgw 将字符串解析为URI: Uri uri = Uri.parse("https://www.youtube.com/channel/UCAoMPWc
我只需要将字符串解析为URI:
Uri uri = Uri.parse("https://www.youtube.com/channel/UCAoMPWcQKA_9Af5YhWdrZgw")
String id = uri.lastPathSegment() //UCAoMPWcQKA_9Af5YhWdrZgw
将字符串解析为URI:
Uri uri = Uri.parse("https://www.youtube.com/channel/UCAoMPWcQKA_9Af5YhWdrZgw")
String id = uri.lastPathSegment() //UCAoMPWcQKA_9Af5YhWdrZgw
这是您可以用来捕获频道id的模式,这也将验证url
^(?:(http|https):\/\/[a-zA-Z-]*\.{0,1}[a-zA-Z-]{3,}\.[a-z]{2,})\/channel\/([a-zA-Z0-9_]{3,})$
我不知道如何在android中执行regex,但是共享regex url,您可以从这里查看
或者是要执行的javascript代码
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 matchs = str.match(pattern);
console.log(matchs[2]);
// output is UCAoMPWcQKA_9Af5YhWdrZgw
希望您能理解。这是您可以用来捕获频道id的模式,这也将验证url
^(?:(http|https):\/\/[a-zA-Z-]*\.{0,1}[a-zA-Z-]{3,}\.[a-z]{2,})\/channel\/([a-zA-Z0-9_]{3,})$
我不知道如何在android中执行regex,但是共享regex url,您可以从这里查看
或者是要执行的javascript代码
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 matchs = str.match(pattern);
console.log(matchs[2]);
// output is UCAoMPWcQKA_9Af5YhWdrZgw
希望您能理解。您可以使用此正则表达式从不同类型的youtube url检索视频ID
String pattern = "(?<=watch\\?v=|/videos/|embed\\/|youtu.be\\/|\\/v\\/|\\/e\\/|watch\\?v%3D|watch\\?feature=player_embedded&v=|%2Fvideos%2F|embed%\u200C\u200B2F|youtu.be%2F|%2Fv%2F)[^#\\&\\?\\n]*";
String pattern=“(?您可以使用此正则表达式从不同类型的youtube url检索视频ID
String pattern = "(?<=watch\\?v=|/videos/|embed\\/|youtu.be\\/|\\/v\\/|\\/e\\/|watch\\?v%3D|watch\\?feature=player_embedded&v=|%2Fvideos%2F|embed%\u200C\u200B2F|youtu.be%2F|%2Fv%2F)[^#\\&\\?\\n]*";
String pattern=“(?subpendu 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})
更新:
这是最短的路:
youtube.com\/channel\/([^#\&\?]*).*
Subhundu 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})
更新:
这是最短的路:
youtube.com\/channel\/([^#\&\?]*).*
删除https://www.youtube.com/channel/
(显然)。有什么问题?url来自用户输入,因此也需要检查url。然后有两个单独的任务:1)检查url(是否有https://www.youtube.com/channel/
);2)删除https://www.youtube.com/channel/
删除https://www.youtube.com/channel/
(显然)。有什么问题?url来自用户输入,因此也需要检查url。然后有两个单独的任务:1)检查url(是否有https://www.youtube.com/channel/
);2) 删除https://www.youtube.com/channel/