What puzzles me the most about the question is why you'd specifically want to use the regex engine for this problem. It doesn't seem like a really bad fit, but it's not a particularly good one either. I'd be more inclined to use some multilevel hash entanglement to attack this problem domain.