![]() |
|
Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re: solution wanted for break-on-spaces (w/specifics)by vr (Curate) |
on Oct 23, 2021 at 23:06 UTC ( #11137929=note: print w/replies, xml ) | Need Help?? |
10 minutes update: aargh, added negative look-behind to cover your 14th case (and added my third). Maybe there are more to add. Next morning update. As LanX pointed out, negative look-behind for just a single backslash isn't enough. Then to save this answer (I like how the "keep" \K meta-character helps in regexp for split, it's kind of interesting), maybe it's easier to revert $quoted to as it was borrowed from $RE{quoted}, and tweak the $re:
I hope it works now, my 1st attempt at this "update" was broken (see, but better not -- nothing interesting -- below. Sorry for the mess.). But further, it's unclear whether to split on escaped space, or several spaces in a row.
And later (final(?)) update: Sigh... damn lack of practice. So this:
passes all tests in LanX's later answer except #2 and is somewhat optimized. About test #2: consensus is "the brief is unclear", must split-like behaviour generate an empty leading field for #2? Expression to split on is definitely not missing nor space literal. If, nevertheless, it must not (as my solution does, failing #2), then my bad, but still, yeah, this regexp is "working" and can be used to literally split on. :)
In Section
Seekers of Perl Wisdom
|
|