in reply to Re^2: split on delimiter unless escaped
in thread split on delimiter unless escaped

So the following seems to do exactly what I want, but doesn't handle empty fields. It might not matter, because my input shouldn't have any empty fields. I'll probably just check that my input string doesn't begin or end with a delimiter, or have two consecutive delimiters in the middle anywhere. If it does, it's bad input, and I can just throw it out. Would still be fun to know how to handle empty fields, though...

my $re = qr{ (?> # don't backtrack into this group !! # either the escape character, # followed by an escape character | # or !; # escape followed by delimiter char | # or [^;\n] # a character that is neither delimiter # character or a newline )+ }x; while(<>) { chomp; my @aray; $str = $_; print "$_\n "; while ($str =~ /($re)/g) { $s = $1; $s =~ s/!!(?=(!|;|\z))/!/g; push( @aray, $s ); } print join(' | ', @aray) . "\n"; }