Darryl Ross wrote: > Hey All, > > I have a string that looks like this: > > {key1,val1},{key2,val2},{key3,val3},{key4,val4},{key5,val5},... > > I'm trying to write a regular expression which can split up that string > and give me a hash back. There are a few gotchas though: > > - The key and/or the value may or may not be inside quotes, > > - The key and/or the value may contain a comma (it will be quoted if > it does), > > - There can be a varying number of key/value pairs, including only > one pair, > > - The values may be key/value pairs themselves. > > My first attempt was something like: /({[^}]+,[^}]+})+/ > > But that completely fails at least the last point, if not the others. > > Does anyone have any ideas (or pointers to good documentation)?
I'd either use one of the Text::CSV modules or multiple REs to break it down and split it up and restore the break down. EG: Change quotes to A and B, change commas between A and B to C, split on ','s and then for each field - restore the A, B and C chars (where A = \001, B = \002 and C = \003). _______________________________________________ Perl-Unix-Users mailing list Perl-Unix-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs