0

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!

3
  • Should be like : ^\d+%(?:,\d+%)+$ Commented Nov 14, 2014 at 13:17
  • [] is a character class, use () for grouping Commented Nov 14, 2014 at 13:19
  • You could use this cool resource: txt2re.com Commented Nov 14, 2014 at 13:38

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thats a pretty fast answer, Thank you very much!
Welcome to Stack Overflow. I suggest you to read this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.