正则表达式解析 youtube yid

2022-01-06 00:00:00 regex youtube php

示例网址

http://www.youtube.com/user/Scobleizer#p/u/1/1p3vcRhsYGo
http://www.youtube.com/watch?v=cKZDdG9FTKY&feature=channel
http://www.youtube.com/watch?v=yZ-K7nCVnBI&playnext_from=TL&videos=osPknwzXEas&feature=sub
http://www.youtube.com/ytscreeningroom?v=NRHVzbJVx8I

任何可以从所有 4 个用例中提取正确 YID 的正则表达式?第一种情况特别奇怪.

Any regex that will pull the correct YID from all 4 of these use cases? The first case is especially odd.

谢谢.

推荐答案

(?<=v=)[a-zA-Z0-9-_]+(?=&)|(?<=[0-9]/)[^&
]+|(?<=v=)[^&
]+

这有效.http://i.imgur.com/SQJW2.jpg

相关文章