Reputation: 1435
No matter what I just can't figure it out. I can have \d
and then repeat it, but whatever gets repeated either has to have a trailing space, or it doesn't.
I want to be able to match any of the following:
"1"
"1 2"
"1 2 3"
"1 2 3 5 6 7 8 9 9"
(with arbitrary repetition)
But absolutely none of the following:
"1 "
"1 2 "
" 1 2"
" 1 3 4 56 6 "
How can this be done?
Perhaps the language which I would like to validate is simply irregular?
Upvotes: 0
Views: 76
Reputation: 4795
This should work
^(\d\s+)*\d$
String must always end in a digit (no trailing space), for any digit before the end it must be followed by 1 to many spaces (and the initial number cannot be preceded by space)
Upvotes: 1