1
I have this string:
16-8-10-20-30-65
The numbers are random and this is just one example.
I need a regular expression that validates that sequence, captures all numbers before 65, including minus signs and excluding the last sign. That is, in the example given, that 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
) cannot be considered valid. A sequence with a single number (16
) can be considered valid. Following link with some tests: https://regex101.com/r/xF6FV/3/tests
What I managed to put together was this:
^([0-9]+-?)+[^-][0-9]*$
That way, the validation works, but I couldn’t capture the data. That’s possible?
I’m not sure I understand you, but is that what you’re looking for? https://regex101.com/r/xF6FVQ/6
– Mateus