Generating the Shortest Regex Dynamically from a source List of Strings
问题 I have a bunch of SKUs (stock keeping units) that represent a series of strings that I'd like to create a single Regex to match for. So, for example, if I have SKUs: var skus = new[] { "BATPAG003", "BATTWLP03", "BATTWLP04", "BATTWSP04", "SPIFATB01" }; ...I'd like to automatically generate the Regex to recognize any one of the SKUs. I know that I could do simply do "BATPAG003|BATTWLP03|BATTWLP04|BATTWSP04|SPIFATB01" , but list of SKUs can be quite lengthy and I'd like to compress the resulting