Regular expressions consist of a very small set of elements.
- (for example,
a or [ak] or . ), - (for example,
r1|r2 ), - repetitions (for example,
r{3,10} , r+ , r* , r? ). - (e.g.,
(r) ) that may be subjected to repetition or election. - Special offers (e.g.
^ , $ ).
This is more or less if we do not want to add non-consumer expectations and the like, but they are not part of your input example, so I will not consider them.
How long (minimum / maximum) can be?
- 1/1 (atoms are constant in size)
- min (minlen (r) to select r) / max (maxlen (r) for r in options)
- minlen (r) * minrepretition / maxlen (r) * maxrepetition
- minlen (r) / maxlen (r)
- 0 (positional parameters correspond to an empty string).
So, you will need a regular expression parser (as Hugh Botwell said in his answer), which returns you as an abstract syntax tree (absy) of the given regular expression; this paragraph can then be analyzed using the rules that I sketched above to find the minimum or maximum length for a string that this regular expression can match.
source share