Help me about regular expression.

duongca69

New Member
Messages
8
Reaction score
0
Points
1
Hello guys
I need to create a regular expression to valid a string with format: {mediagallery id=[1,8,2,3,4,5,10,6,11,7,...,124]}
If you can, please help me!
Thanks
 

Skizzerz

Contributors
Staff member
Contributors
Messages
2,929
Reaction score
118
Points
63
Can you give a few actual examples of what you are matching? From that one snippet I can't tell if id is supposed to be a comma-separated list, or if id is supposed to be a single number and those numbers are all valid values for it.
 

lompocus

New Member
Messages
1
Reaction score
0
Points
0
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!)
 
Top