Do you mean that you want to determine whether a string's format is "legal," according to the format you posted? Well, assuming those ellipses aren't actually there....
Break down the problem just as you would any other. You have opening and closing brackets of two kinds, right? If you're only checking whether something is enclosed in brackets, then this might work:
/{.*}/
Now we have a word. You can try
/{mediagallery\wid
and add stuff as necessary. I'm still new to this. Hope this was remotely helpful. Start by trying to validate [1, 2, 3, ..., 123]. Keep on adding stuff until you successfully validate everything.
Presumably you want to retrieve the numbers. What I do (reading from perl, so number->string is easy, dunno about anything else) is enclose everything in quotes, then you can loop through pattern checking with
m/'(.*)?'/g or m/'(.*)'/g or something similar
which, presumably, destroys the string being checked in the process.
(First post!)