in reply to Re: Handling escapes while splitting lines
in thread Handling escapes while splitting lines

Aha -- that does it. I like the approach much better (matching non-backslash and colon or 2-character escape sequences).

Running some quick test code:

my $re = shift or die "re expected\n"; while (<>) { chomp; my ($field, $value) = ($_ =~ $re); print "'$_' -> ('$field', '$value')\n"; }
We see that it handles all these cases correctly:
'a:b:c' -> ('a', 'b:c') 'a\:b:c' -> ('a\:b', 'c') 'a\\:b:c' -> ('a\\', 'b:c') 'a\\\:b:c' -> ('a\\\:b', 'c') 'a:' -> ('a', '') ':b' -> ('', 'b')
The only thing it doesn't handle perfectly is the invalid input case with an escaped colon but no delimiter:
'a\:b' -> ('', 'b')
Notice that this is indistinguishable from the ':b' input. The fix is simple though, just anchor the start of the match:
^((?:[^:\\]+|\\.)*):(.*)
For my use this works better, as the match fails, telling me there was no field delimiter present.

Thanks
--mike