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.
In reply to Re^3: Help with regex for complicated key=value string
by ikegami
in thread Help with regex for complicated key=value string
by mscharrer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |