If your regular expression is programmed generated, why not programmatically generate n separate regular expressions and check each of them in turn? If they do not have a common prefix, and the Java regex mechanism is smart, all alternatives will still be tested.
Update: I just looked at the source of Sun Java, specifically java.util.regex.Pattern $ Branch.match (), and also just doing a linear search on all alternatives, each of which tries in turn. Other places where the branch is used do not offer any optimization of common prefixes.
source share