in reply to Re^2: Help with regex for complicated key=value string
in thread Help with regex for complicated key=value string

That would be:
split /(?:$key_pat=)?$val_pat\K,/

Test:

use 5.010; # /\K/ use Data::Dumper; my $str = join ',', <<'__EOI__' =~ /.+/g; key=value\,value key=\\ value __EOI__ my $key_pat = qr/[^=,]+/; my $val_pat = qr/"[^"]+"|(?:[^\\,]|\\[\\,])*/; print Dumper [ split /(?:$key_pat=)?$val_pat\K,/, $str ];

Using split means everything has to be parsed twice. Once to find the commas on which to split and once to find the composing terms.

Update: Simplified pattern slightly.

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.