How could I use LINQ to filter out strings starting with a variety of sub-strings?

.net, c#, linq

Solution

With LINQ:

 List<string> exceptions = new List<string>() { "AA", "EE" };

 List<string> lines = new List<string>() { "Hello", "AAHello", "BHello", "EEHello" };

 var result = lines.Where(x => !exceptions.Any(e => x.StartsWith(e))).ToList();
 // Returns only "Hello", "BHello"

Problem

Let's say I have `var lines = IEnumerable<string>`, and `lines` contains a variety of lines whose first 1..n characters exclude them from a process. E.g lines starting with '*', 'E.g.', 'Sample', etc. The list of exclusion tokens is variable and known only at runtime, so ``` lines.Where(l => !l.StartsWith("*") && !l.StartsWith("E.g.") && ... ``` becomes somewhat problematic. How could I achieve this?

Original source