using System.Collections.Generic;
using System.Text.RegularExpressions;
public static void Main()
var tests = new List<string>()
for (int i = 0; i < tests.Count; i++)
Console.WriteLine((i + 1) + ": " + MatchShippingVendor(tests[i]));
private static string MatchShippingVendor(string vendor)
string pattern = @"[^a-zA-Z\d&]";
var matches = new Dictionary<int, int>();
for (int i = 0; i < Couriers.Count(); i++)
foreach (string search in Regex.Split(vendor, pattern).Where(s => !string.IsNullOrWhiteSpace(s)))
if (Couriers[i].Split(' ').Any(s => string.Equals(s, search, StringComparison.InvariantCultureIgnoreCase)))
matches.Add(i, matchCount);
if (matches.Any(m => m.Value > 0))
var bestMatches = matches.Where(m => m.Value == matches.Values.Max()).ToDictionary(x => x.Key, x => x.Value);
if (bestMatches.Count > 1)
var directMatches = bestMatches.Where(m => Couriers[m.Key].Split(' ').Count() == m.Value).ToDictionary(x => x.Key, x => x.Value);
if (directMatches.Count == 1)
return Couriers[directMatches.First().Key];
return Couriers[bestMatches.First().Key];
public static string[] Couriers = new[]