正则 截取URL 网址字符
Regex reg = new Regex(@"(?imn)(?<do>http://[^/]+/)(?<dir>([^/]+/)*([^/.]*$)?)((?<page>[^?.]+\.[^?]+)\?)?(?<par>.*$)"); var filename =string.Empty; var fileurl = string.Empty; plate.WalkThroughUrl ="http://47.104.9.158/upload/Report/Temp/202204/20220407142558029.xls"; //正则过滤全路径前面的地址 保留短路径 MatchCollection mc = reg.Matches(plate.WalkThroughUrl); foreach (Match m in mc) { fileurl = m.Groups["dir"].Value;//upload/ReportTemp/202203/ filename = m.Groups["par"].Value; //20220330172440919.xls } plate.WalkThroughUrl ="/"+ fileurl + filename;
来源 https://blog.csdn.net/weixin_33913332/article/details/86038571 地址