For some simple regular expressions like the ones you provided (AB [CD] 1234), there is a limited set of matches. But for other expressions (AB [CD] * 1234) the number of possible matches is not limited.
One way to identify all the possibilities is to determine where in the regular expression there is a choice. For each possible choice, create a new regular expression based on the original regular expression and the current selection. This new regular expression is now slightly simpler than the original.
For an expression like "A [BC] [DE] F", the method will act as follows
getAllMatches("A[BC][DE]F") = getAllMatches("AB[DE]F") + getAllMatches("AC[DE]F") = getAllMatches("ABDF") + getAllMatches("ABEF") + getAllMatches("ACDF")+ getAllMatches("ACEF") = "ABDF" + "ABEF" + "ACDF" + "ACEF"
midtiby
source share