When I get really zoned in on a problem I can't sleep, or rather I do sleep, but it seems that somehow the topic in my head becomes the makings of some really interesting dream. I've always had mild insomnia, so I'm capable of sleeping and dreaming right on the edge of the asleep/wake border. I've often found myself with an actual dream continuing even as I wake up and become conscious enough to do stuff around my house. Definitely not something I recommend to others.
My point? Well, I kept thinking about this problem of decomposing the ranges into expressions. ALL NIGHT. My brain kept telling me that some additional items would be nice to add. Namely, the creation of range coverage print-outs for each of the generated range decompositions (if you note the ranges are doing things like covering 0-9, then 10 through 99, then 100 through 999, etc... That is the way things get decomposed. Unfortunately doing it this way does leave one single spot for error. A number such as 001 will match \d?\d?\d. If you wanted something that threw on leading zeros, you'd have to add more to the expressions.
Since they break down this way, it becomes easy to take our expressions and turn them back into the ranges that they would match. I'm not talking about the standard ranges of say 0 through 5000, but the actual saturation ranges of 0 through 9, 10 through 99, etc..., so you know that every inch of your range has actually been covered and that your algorithm isn't screwing up.
The second thing I kept coming to was the concept that merging two ranges wouldn't be that hard, or merging N arbitrary ranges. The concept would be finding any ranges that overlap, and then merging their contents to produce a new match group that would match the expanded range or set of ranges. Then I thought, hell this is nothing more than a subset of set theory. I think that was the point I was trying to make. You see Darren has been wanting a way into set theory, and I think he found it. Each of the expressions we are forming denotes a set, and the key is to find if all members in the set defined by the range are also present in at most one other set that represents are decomposed expression. Note the keywords there.
X is our target number X is in the set of { rangestart..rangeend }
Y is our expression Y is the superset of all sets { decomposed1..decomposedn }
All T in X must be a member of Y additionally all T in X must be a member of at most one decomposed and not more
All T not in X must not be a member of Y
Y is just a cute way of aliasing the set X, or is it? Your Y is based on your decomposed expressions, so it becomes possible for Y and X to be different sets. In fact, if you are using optional matching Y may match string representations of integers that don't exist in the integer set X. However, Y and X will still have the same footprint if viewed in the light of integer value only. After all, there is an int.Parse somewhere in the implementation and outside of the theory.
Still looking for a darn math mark-up tool. I've seen the MathML crap, but it requires a specialized viewer. There are a couple of math packages that export in HTML and maybe those would work. I'll have to keep my eyes open and find something, since the above looks a lot better in set notation than it does in written out verbose American English.