猿问

我怎样才能将部分 url 与 c#

桃花长相依
浏览 67回答 1
1回答

吃鸡游戏

试试这个使用正则表达式的方法:static void Main(string[] args){  var urls = new string[] { "https://www.example.com/*/post/", "https://www.example2.com/videos/*" };  // here regex patterns are created: special characters are escaped and   // star, which means here "anything" is replaced by .+ which means "one or more of any charaters"  var regexes = urls.Select(url => new Regex(url.Replace("/", @"\/").Replace(".", @"\.").Replace("*", ".+")));  var toCheck = new string[]  {  "https://www.example.com/user123/post/",  "http://www.example.com/user123/post/abc",  "https://www.example2.com/videos/1234",  "https://www.example2.com/videos/1234/5678",  "http://www.example2.com/videos/1234/5678",  "http://example2.com/videos/1234/video.asp?id=1"  };  var valid = toCheck.Where(url => regexes.Where(r => r.Match(url).Success).Any()).ToArray();}
随时随地看视频慕课网APP
我要回答