Partitioning string into longest substrings of given characters
You could do:
StringCases[
"ABCDEFGH",
Longest[p__] /; StringMatchQ[p,("D"|"F"|"G")..|("D"|"E"|"H")..|("A"|"B"|"C"|"G")..]
]
{"ABC", "DE", "FG", "H"}
But
Alternatives
should be from definition something that is independent on arguments order.
StringCases
is based on the PCRE regular expression engine for which it isn't true: a regex engine always returns the first match from listed in alternation (when it allows to match the whole pattern).
To get the behavior you expected you should use SequenceCases
instead (which doesn't use regexes and is based on Mathematica's own pattern-matcher):
StringJoin @@@
SequenceCases[
Characters@"ABCDEFGH",
{Longest[("D" | "F" | "G") .. | ("D" | "E" | "H") .. |
("A" | "B" | "C" | "G") ..]}]
{"ABC", "DE", "FG", "H"}