C#来自URL的正则表达式信息

C#来自URL的正则表达式信息,c#,.net,C#,.net,我有以下网址: http://vk.com/video#/video219171498_166164529 http://vk.com/video?gid=21095903#/video-21095903_165699050 http://vk.com/video#/video219171498_166164529 我需要从这些字符串中获取信息“video219171498_166164529”。也许有一种代码可以在视频和19个符号之后拍摄。对不起,我讲的是英语您实际上只需使用Split(

我有以下网址:

http://vk.com/video#/video219171498_166164529

http://vk.com/video?gid=21095903#/video-21095903_165699050

http://vk.com/video#/video219171498_166164529

我需要从这些字符串中获取信息“video219171498_166164529”。也许有一种代码可以在视频和19个符号之后拍摄。对不起,我讲的是英语

您实际上只需使用
Split()
即可获得值


请务必添加错误处理

以改进491243的答案,我想这样做:

 string _str = "http://vk.com/video#/video219171498_166164529";
 string _arr = _str.Split("/").Last();

我不确定你的问题的标题是否重要,但是为了延伸到其他人的有效答案,如果你确实需要(?)使用正则表达式,你可以获得与其他人相同的结果。C#使用System.Text.RegularExpressions,因此您可以执行类似操作来提取“video…”字符串

在上面的示例中,结果将等于url中的匹配字符串。首先使用Match检查是否存在匹配意味着您可以将其放入循环并遍历列表/数组等,而无需知道url值,或者更改特定情况下的模式


无论如何,您可能不需要正则表达式,但如果您需要,我希望上面的内容能有所帮助。

到目前为止您尝试了什么?是的,我可以从第一个链接中获取,但我无法为所有这些链接编写代码
string _str = "http://vk.com/video#/video219171498_166164529";

var index = _str.LastIndexOf("/");
var value = _str.SubString(index + 1);
 string _str = "http://vk.com/video#/video219171498_166164529";
 string _arr = _str.Split("/").Last();
string pattern = "(video[\w-]+)";
string url = "http://blahblah/video-12341237293";

Match match = Regex.Match(url, pattern);
// Here you can test Match to check there was a match in the first place
// This will help with multiple urls that are dynamic rather than static like the above example

string result = match.Groups[1].Value;