I've written something similar for regular expressions matching DNA/Protein sequences where {n,m} combinations are expanded. I could allow '.' since, in my case, '.' referred to a limited alphabet. I needed all the specific permutations because I also needed to allow some mismatches relative to a specific permutation. If I ever come back to it I'll check out your code for possible improvements to my implementation.