Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Help with regex for complicated key=value string

by kvale (Monsignor)
on Oct 29, 2008 at 18:49 UTC ( #720293=note: print w/ replies, xml ) Need Help??


in reply to Help with regex for complicated key=value string

I would split on everything that is not a bare comma (untested):

my $q_str = qr("[^"]*"); # quoted string my $unq_nc_str = qr([^",]+); # string with no quotes or commas my $esc_com = qr(\\\\,); # escaped comma my @bits = grep {$_ ne ','} split /((?:$q_str|$unq_nc_str|$esc_com)+)/, $line;
By grouping the split regex, we get split bits as well as bare commas. Then we filter bare commas. This assumes that quotes are not nested.

-Mark


Comment on Re: Help with regex for complicated key=value string
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://720293]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (16)
As of 2015-07-06 13:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (74 votes), past polls