I want to match strings with two numbers of equal length, like : 42-42
, 0-2
, 12345-54321
.
I don't want to match strings where the two numbers have different lengths, like : 42-1
, 000-0000
.
The two parts (separated by the hyphen) must have the same length.
I wonder if it is possible to do a regexp like [0-9]{n}-[0-9]{n}
with n
variable but equal?
If there is no clean way to that in one pattern (I must put that in the pattern attribute of a HTML form input), I will do something like /\d-\d|\d{2}-\d{2}|\d{3}-\d{3}|<etc>/
up to the maximum length (16 in my case).