in reply to Optimize Percentage validation
The first rule of optimisation is "Make it work first". Your regex does not even compile, the closing '/' being missing.
Once you have fixed that, it still will exlude 9, 10, 99 etc. and allow 99.999, 99.9999 etc.
Once you made the grouping conditional, and anchored the end of the regex, it will probably work, and you could probably save a few microseconds by making the grouping non-capturing.
But really--how many times are you going to run this test that you need to optimise it?
Which then makes me wonder what question you are really asking?
If the former, ask that question--and forget the "optimize" imperative.
If the latter, it is certainly possible, but it would probably run more slowly that the two-part test.
|
|---|