Reputation: 505
I have to specify a pair of ports using format "number1-number2". Number1 and number2 both in range [0-65535]. But number2 is always larger than number1.
Is it possible to make a regular expression to expression the logic "number2 is always larger than number1".
Upvotes: 2
Views: 1153
Reputation: 6800
Extracting numbers should be your first choice, because it's the best choice. There's no good way to do this in regular expressions alone. You should use
\\[(\\d+)-(\\d+)\\]
to extract those two numbers and compare them. The conversion from string to integer is miniscule in cost, and pales in comparison to how expensive any regex that might approach what you need would be. We're talking massive polynomial exponents versus linear time.
Upvotes: 1