使用正则表达式解析 URL [英] Parse URL using Regex

查看:60
本文介绍了使用正则表达式解析 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 Youtube 和 Dailymotion 视频 URL,如下所示:

I have Youtube and Dailymotion Video URL as follows:

对于优酷

对于 Dailymotion

For Dailymotion

我想获得这些视频的预览图像,所以我必须按如下方式解析这些链接:

I want to get the Preview image of these video, So i have to parse these link as follows:

对于优酷

对于 Dailymotion

For Dailymotion

请帮帮我.我是正则表达式的新手...

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆