Reputation: 11
i was wondering if anybody could help me with a RegEx i need to use for matching strings in the format "4%,6%,8%,9%" "(Number)(Percentage)(comma)(number)(percentage)....N"
I tried hard to get this one ^[\d*(?:%),]+$
but its matching the format "4%,2,6,5%"
(numbers without percentage simbol).
Thanks in advance!
Upvotes: 0
Views: 52
Reputation: 174786
Change your regex like below,
^\d+%(?:,\d+%)+$
(?:,\d+%)+
Allows one or more strings of this ,<number>%
format.
OR
^\d+%(?:,\d+%)*$
(?:,\d+%)*
Allows zero or more strings of this ,<number>%
format.
Upvotes: 2