Starting from the premise that a lame but almost working answer is better than none:

/( #A nice simple capture, for [^|\{]+ #a block of nonsignificant chars | \{ [^}]+ \} #or a bracketed block ) \| #followed by a pipe. /x

Doesn't _quite_ work - produces the following on output:

$VAR1 = [ '', 'foo', '', '{baz|qux}', 'fax' ];

This indicates my need for enlightenment - if I use (?:) instead of (), it returns just (' ',' ','fax'), not the captures... so maybe there's some deeper magic going on in split which I'm not clear on.

Update: Found why it's adding the captured elems, but not why using (?:) breaks it.

from split manpage:

If the PATTERN contains parentheses, additional list elements are crea +ted from each matching substring in the delimiter.

Update again: Now I fool feelish. Okay, yup, like would make sense, split uses pre/postmatch stuff - the end result being that since (?:) is part of the match, it gets dropped, and since that's the content I'm looking for (the foo or {bar|baz} bit), I lose my content.

hm. now I'm as stumped as BUU. Can't use lookbehinds, cuz variable length lookbehinds aren't implemented... *falls into contemplative silence*.

But is that approximately what you're looking for?


In reply to Re: Split unless contained by by Ferret
in thread Split unless contained by by BUU

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.