C# Regular Expression excluding a string

后端 未结 3 1796
-上瘾入骨i
-上瘾入骨i 2021-01-02 20:03

I got a collection of string and all i want for regex is to collect all started with http..

href=\"http://www.test.com/cat/1-one_piece_episodes/\"href

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-02 20:48

    Your input doesn't look like a valid string (unless you escape the quotes in them) but you can do it without regex too:

    string input = "href=\"http://www.test.com/cat/1-one_piece_episodes/\"href=\"http://www.test.com/cat/2-movies_english_subbed/\"href=\"http://www.test.com/cat/3-english_dubbed/\"href=\"http://www.exclude.com\"";
    
    List matches = new List();
    
    foreach(var match in input.split(new string[]{"href"})) {
       if(!match.Contains("exclude.com"))
          matches.Add("href" + match);
    }
    

提交回复
热议问题