Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Help with regex for complicated key=value string

by kvale (Monsignor)
on Oct 29, 2008 at 18:49 UTC ( [id://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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-03-29 07:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found