mikecarlton has asked for the wisdom of the Perl Monks concerning the following question:
which turns "a:b" into ('a', 'b').my ($field, $value) = $_ =~ /^(.*?):(.*)$/
This works fine, but I also want to allow backslash escapes, in particular '\:' should not be a field delimiter, e.g. splitting "a\:b:c" should return ('a:b', 'c').
I believe the logic should be "match on a colon not preceeded by an odd number of consecutive backslashes" (doubled backslashes are a literal backslash). My logic is to match pairs of backslashes greedily, then a : not following a backslash, i.e.
my ($field, $value) = $_ =~ /^(.*(?:\\\\)*)(?<!\\):(.*)$/
But this and many other variations don't work. Suggestions?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Handling escapes while splitting lines
by tye (Sage) on Jan 19, 2005 at 02:41 UTC | |
by mikecarlton (Novice) on Jan 19, 2005 at 05:35 UTC | |
|
Re: Handling escapes while splitting lines
by Limbic~Region (Chancellor) on Jan 19, 2005 at 01:44 UTC | |
by Eimi Metamorphoumai (Deacon) on Jan 19, 2005 at 02:05 UTC | |
by Limbic~Region (Chancellor) on Jan 19, 2005 at 13:25 UTC | |
|
Re: Handling escapes while splitting lines
by demerphq (Chancellor) on Jan 19, 2005 at 09:00 UTC |