第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

我怎樣才能將部分 url 與 c#

我怎樣才能將部分 url 與 c#

C#
桃花長相依 2022-12-31 11:21:30
我有一個(gè)動態(tài)列表,如下幾行https://www.example.com/*/post/https://www.example2.com/videos/*https://www.example3.com/photo/我如何匹配 C# 以下 url(返回 true)https://www.example.com/user123/post/http://www.example.com/user123/post/abchttps://www.example2.com/videos/1234https://www.example2.com/videos/1234/5678http://www.example2.com/videos/1234/5678http://example2.com/videos/1234/video.asp?id=1也許我可以使用 UriTemplate 但 url 有很多部分。他們沒有靜態(tài)格式。
查看完整描述

1 回答

?
吃雞游戲

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超7個(gè)贊

試試這個(gè)使用正則表達(dá)式的方法:


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();

}


查看完整回答
反對 回復(fù) 2022-12-31
  • 1 回答
  • 0 關(guān)注
  • 98 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號