0
Input:"[3, 4]", "[1, 2, 7, 7]"
Input:"[13, 4]", "[1, 2, 3, 6, 14]"
Input: "[5, 5]", "[1, 2, 3]"

\"\s*\[[0-9]\s*\,\s*[0-9]\]\"\s*\,\s*\"\[[0-9]\s*\,

This was what I tried to validate the above inputs. with what I tried I couldn't get the last part of the string validated. the second array of data can be any number of inputs. The above regex applies until the first comma of the second array. couldn't now write a general expression for any number of inputs after that.

5
  • the above inputs. ... are they literally "[3, 4]", "[1, 2, 7, 7]" ... including " and [] - check this Commented Oct 15, 2020 at 4:46
  • Yes they are. I checked the one you mentioned. but no. That is not it. I need the full string to be validated including all the "" [] and , Commented Oct 15, 2020 at 5:05
  • I know ... I was showing you what yours does in a place you can fiddle with it and get it right :p Commented Oct 15, 2020 at 5:08
  • I use it to build regex. but the question was that I couldn't do the final part Commented Oct 15, 2020 at 5:33
  • OK, didn't realise, sorry to waste your time Commented Oct 15, 2020 at 5:36

1 Answer 1

1

If I understand correctly

^\s*"\s*\[\s*[0-9]+\s*(?:\,\s*[0-9]+\s*)*\]\s*"(?:\s*,\s*"\s*\[\s*[0-9]+\s*(?:\,\s*[0-9]+\s*)*\]\s*")*\s*$

https://regex101.com/r/PpZy8I/1

 ^                  # Begin of string     
 \s*                # Leading wsp
 " \s*              # Quote start of array
 \[                 # Array opening
 \s* [0-9]+ \s* 
 (?:                # Optional nesting elements comma plus digits
    \, \s* 
    [0-9]+ \s* 
 )*
 \]                 # Array close
 \s* 
 "                  # Quote end of array    
 
 (?:                # Optional many more arrays
    \s* , \s* 
    " \s* 
    \[ 
    \s* [0-9]+ \s* 
    (?:
       \, \s* 
       [0-9]+ \s* 
    )*
    \] 
    \s* 
    "     
 )*
 \s*                # Trailing wsp
 $                  # End of string
Sign up to request clarification or add additional context in comments.

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.