本文介绍了使用正则表达式解析 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有 Youtube 和 Dailymotion 视频 URL,如下所示:
I have Youtube and Dailymotion Video URL as follows:
对于优酷
- http://www.youtube.com/v/0PsnoiwMrhA
- http://www.youtube.com/watch?v=ok_VQ8I7g6I
- http://www.youtube.com/watch?v=1taai0d1FXw&list=PL1uGXsv9VLdCm_LYVa9c7Rv8DPdflJZfT
对于 Dailymotion
For Dailymotion
- http://www.dailymotion.com/video/x21a1i8_brazil-1-7-germany-a-world-cup-2014-brick-by-brick-video-animation_news
- http://www.dailymotion.com/video/x2148xg_brazil-1-7-germany-brazil-player-ratings-from-a-shocking-defeat_sport
我想获得这些视频的预览图像,所以我必须按如下方式解析这些链接:
I want to get the Preview image of these video, So i have to parse these link as follows:
对于优酷
- http://img.youtube.com/vi/0PsnoiwMrhA/default.jpg
- http://img.youtube.com/vi/ok_VQ8I7g6I/default.jpg
- http://img.youtube.com/vi/1taai0d1FXw/default.jpg
对于 Dailymotion
For Dailymotion
- http://www.dailymotion.com/thumbnail/video/x21a1i8_brazil-1-7-germany-a-world-cup-2014-brick-by-brick-video-animation_news
- http://www.dailymotion.com/thumbnail/video/x2148xg_brazil-1-7-germany-brazil-player-ratings-from-a-shocking-defeat_sport
请帮帮我.我是正则表达式的新手...
Please help me. I'm newbie in regex...
推荐答案
YouTube:
ResultString = Regex.Replace(SubjectString, "http.*?v[=/]([^\s&#]+)\S+", "http://img.youtube.com/vi/$1/default.jpg", RegexOptions.IgnoreCase)
DailyMotion:
一个简单的字符串替换就可以了,但这里是正则表达式:
A simple string replace would do, but here is the regex:
ResultString = Regex.Replace(SubjectString, "http://www\.dailymotion\.com/video/", "http://www.dailymotion.com/thumbnail/video/", RegexOptions.IgnoreCase)
这篇关于使用正则表达式解析 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!