text: Q:
  
  C# intersect two list of strings with a pattern
  
  I have two list of strings like this:
  var entities= new List<string>(){"101", "102", "103",}; 
  var files= new List<string>(){"101_F05_20101001.csv", "102_F05_20101001.csv", "201_F05_20101001.csv", "202_F05_20101001.csv"};
  
  I want to get the result of intersecting them following this pattern:
  ID_F05_YYYYMMDD.csv
  Where ID should match one or more items in the entities list.
  I have written the following code:
  var list = files
      .Where(x => entities.Any(y => x.Contains(y) && x.Substring(0, y.Length) == y))
      .ToList();
  
  Running code here.
  But I wonder if this can be improved using a regex like this one:
  var regex = new Regex(@"^(\d*)_F05_\d*\.csv$");
  
  Is it possible?
  
  A:
  
  You may use
  .Where(x => Regex.IsMatch(x, $@"^(?:{string.Join("|", entities)})_F05_\d*\.csv$"))
  
  The regex will look like ^(?:101|102|103)_F05_\d*\.csv$ given your current input data and it will match
  
  ^ - start of string
  (?:101|102|103) - a non-capturing group that matches 101, 102 or 103
  _F05_ - a literal string
  \d* - 0 or more digits
  \.csv - .csv string
  $ - end of string
  
  Note you do not need to regex escape the entities if they are numeric. Else, you need to use string.Join("|", entities.Select(Regex.Escape)).
  C# code demo:
  var entities= new List<string>(){"101", "102", "103",}; 
  var files= new List<string>(){"101_F05_20101001.csv", "102_F05_20101001.csv", "201_F05_20101001.csv", "202_F05_20101001.csv"};
  
  var pat = $@"^(?:{string.Join("|", entities)})_F05_\d*\.csv$";
  
  var list = files
          .Where(x => Regex.IsMatch(x, pat))
          .ToList();
  
  foreach (var s in list) {
      Console.WriteLine(s);
  }
  
  Output:
  101_F05_20101001.csv
  102_F05_20101001.csv
  
  