in reply to Split unless contained by

How would i construct a regex, to feed to split i would guess, so i could split on any pipe thats not contained by brackets?

You needn't use split(). A regex is sufficient:

my $str = "foo|{baz|qux}|fax"; my @parts = $str =~ /( \{.+?\} # e.g., {baz|qux} | [^|]+ # e.g., foo ) (?:\||$) # |, or end of string /xg; $" = "\n"; print "@parts"; __END__ foo {baz|qux} fax

Replies are listed 'Best First'.
Re: Re: Split unless contained by
by Ferret (Scribe) on Aug 09, 2002 at 23:40 UTC

    Hah. Caught using a pair of pliers when I needed a hammer. Hats off to you, dws and belkajm.

Re: Re: Split unless contained by
by BUU (Prior) on Aug 10, 2002 at 01:55 UTC
    Indeed, ++ to dws, this works perfectly, my thanks.