But finally I got it. I really hope that it will save someone just a small part of the time it took me to figure.
If anyone can do it one line I would like to know, this is a kind of hack, though a good one.
The regexp says: split on & preceded by any even number of backslashes, which is not preceded by a síngle backslash. The idea is to find a uneven number or backlashes. Unfortunately the implementation of split is less than perfect which is why the second line is needed. It cleans up the extra fields that get produced.
think perl for perl is the most elevated
/dh
@a = split /(?<!\\)(\\\\)*&/, "a=1&b=2\\&3&c=4"; $a[$_] .= splice @a, $_ + 1, 1 for (0..($#a/2));
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: split unless escaped
by Anonymous Monk on Apr 25, 2000 at 20:02 UTC | |
|
RE: split unless escaped
by Anonymous Monk on Apr 25, 2000 at 20:10 UTC | |
by ZZamboni (Curate) on Apr 25, 2000 at 21:15 UTC | |
|
RE: split unless escaped
by nuance (Hermit) on May 08, 2000 at 03:35 UTC | |
|
RE: split unless escaped
by anders (Initiate) on May 26, 2000 at 19:57 UTC |