Regex to match multiple strings

If you can guarantee that there are no reserved regex characters in your word list (or if you escape them), you could just use this code to make a big word list into @"(a|big|word|list)". There’s nothing wrong with the | operator as you’re using it, as long as those () surround it. It sounds like the \w* and the \b patterns are what are interfering with your matches.

String[] pattern_list = whatever;
String regex = String.Format("({0})", String.Join("|", pattern_list));

Leave a Comment