What kinds of strange oddities would I be talking about? Well, check out the following oddity:
699 through 700
699|700
699 through 701
699|70[01]
699 through 718
699|70\d|71[0-8]
698 through 701
69[89]|70[01]
You start to get the picture. There are some oddities when the max value has 0's and the min value has 9's that lead the right edge of the ranges. A standard algorithm as I had outlaid before would do the following:
699 through 700
leftmost = 0
starti = min.Length - 1 = 2
69[9-9]|70[0-0]|6[9-9]\d|7[0-0]\d
You see the problem? Based on the algorithm of simply finding the leftmost variable character isn't enough, since we also have some dependence on the rightmost character. There is one solution we can code in, only process a pattern possibility if the character isn't an extreme character. For the lower bound ranges extremes are 9's and for upper bound extremes are 0.
699 through 700
leftmost = 0, starti =min.Length - 1=2, skip starti = 2 and starti = 1 based on extremes
go to final range processing (step 5). Since max-min is now only 1, we won't add any patterns. A null result-set?
What our algorithm really needed to be was 699|700. However, based on our rules, that won't happen. Another rule, then might be that we add the pattern if we've approached (i-1) == leftmost.
699 through 708
leftmost = 0, starti = min.Length - 1 = 2
starti = 2, skip 9 in 699, process 8 in 708, results 70[0-8]
starti = 1, skip by default, hit rule (starti-1)==leftmost, same for 708, results 699|708
So we need another rule. Only process the default pattern if we haven't already processed a pattern. By that means, the end result is now 699|70[0-8]. Darn, we start to add a large number of rules to the generation of the range alternation group. There are still some items I haven't fully made elegant yet, as I've recently realized. Take the following:
699 through 710
699|70\d|710
By our default rule of only processing non-zero digits would exclude us from creating 70\d (actually it wouldn't, since our code would skip it the first time through and then create it the second time through using one of the exceptions). Since 70\d gets created as an exception 710 never gets created.
I'll leave these thoughts with you. I'm still waiting for some algorithms to show up!