3

Can you help me with expression for array: ["232","2323","233"]
I try this: /^\[("\d{1,7}")|(,"\d{1,7}")\]$/
But this expression is not working properly.
I use ruby(rails).

1
  • 2
    what is the expected output || what do you want to match? Commented Jan 15, 2013 at 12:01

3 Answers 3

1

This would validate the array structure well, blocking an entry like [,"123"]

^\[(("\d{1,7}")(,"\d{1,7}")*)?\]$
Sign up to request clarification or add additional context in comments.

Comments

1

You may try this ( though it may allow leading ,):

^\[(,?"\d{1,7}")*]$

5 Comments

Why a , before the opening " and after the closing "?
@NaveedS - Unintentionally added. My description was right, but forgot to remove one of the ,
Note this may capture an empty array as well.
@YamMarcovic empty array is allowed I think. @manojlds I suggest a correction ^\[(("\d{1,7}")(,"\d{1,7}")*)?\]$ as it validates the array well. My suggestion for the edit was rejected.
@NaveedS And perhaps even more functional. :) Was just stating a fact to be aware of.
0

Try this: /^\[("\d{1,7}")(, ?"\d{1,7}")*\]$/

Comments

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.