string tempStr = "https://www.iesdouyin.com/share/video/6676982969124588814/?region=CN&mid=6677099342060456712&u_code=jlhdj79k&titleType=title&utm_source=copy_link&utm_campaign=client_share&utm_medium=android&app=aweme×tamp=1560296676";
Regex regex = new Regex("/video/(?<video>\\d+?)/");
Match match = regex.Match(tempStr);
if (match.Success){
//Groups的序号是从1开始的,0有特殊含义
Console.WriteLine(match.Groups[1].Value);
Console.WriteLine(match.Groups["video"].Value);
//0 打印的是:/video/6676982969124588814/
Console.WriteLine(match.Groups[0].Value);
}
上面的也可以简写成这样(少量字符串提取):
string tempStr = "https://www.iesdouyin.com/share/video/6676982969124588814/?region=CN&mid=6677099342060456712&u_code=jlhdj79k&titleType=title&utm_source=copy_link&utm_campaign=client_share&utm_medium=android&app=aweme×tamp=1560296676";
Match match = Regex.Match(tempStr, "/video/(?<video>\\d+?)/");
if (match.Success){
//Groups的序号是从1开始的,0有特殊含义
Console.WriteLine(match.Groups[1].Value);
Console.WriteLine(match.Groups["video"].Value);
//0 打印的是:/video/6676982969124588814/
Console.WriteLine(match.Groups[0].Value);
}
循环提取
string str1 = "16894691be5bc8ea973e61d55b7d63e8db1479ea";
Regex regex = new Regex("\\d+");
MatchCollection matchs = regex.Matches(str1);
foreach (var item in matchs) {
Console.WriteLine(item);
}