So this is a bit unusual use of RegEx; I want to calculate number (or indicate infinite if suitable) of distinct strings that would be matched by a specific pattern.
For example let's consider [a-zA-Z]
which would yield 52, [a-zA-Z]{1,2}
which would yield 2652 (52+52×52−52×2; subtracting 52×2 for strings like aa
,MM
which are not distinct) or [a-zA-Z]+
which would be ∞.
Of course I'd like this mechanism to be able to deal with more complex regular expressions than that. I'm particularly interested in solutions for PHP and Ruby. Is this even possible?