I have this string:
16-8-10-20-30-65
The numbers are random and this is just an example.
I need a regular expression that validates this sequence, capture all the numbers before 65, including minus signs and excluding the last signal. That is, in the given example, this would be 16-8-10-20-30
.
Sequences that end with a hyphen ( 16-8-
) or have more than one hyphen between two numbers ( 16-8--22
) can not be considered valid. A sequence with a single number ( 16
) can be considered valid. Follow the link with some tests: link
What I was able to put together was this:
^([0-9]+-?)+[^-][0-9]*$
In this way, validation works, but I was unable to capture the data. Is this possible?