Ah, neat. I made a couple of small modification, and now I'm very close. The trouble left now is how to capture an empty field - i.e. where I have two delimiter characters next to each other I should emit an empty chunk, instead of no chunk. Still stuck on that. What I have so far:
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; $str = $_; print "$_\n"; while ($str =~ /($re)/g) { print " Chunk '$1' => "; $s = $1; $s =~ s/!!(?=(!|;))/!/g; print "$s\n"; } }
Example of paired delimiters (;;)
a!!val!!;;bv!!al;; Chunk 'a!!val!!' => a!!val!! Chunk 'bv!!al' => bv!!al
In reply to Re^2: split on delimiter unless escaped
by yrp001
in thread split on delimiter unless escaped
by yrp001
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |