Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Complex Splitting

by Roy Johnson (Monsignor)
on Feb 06, 2007 at 15:54 UTC ( [id://598566]=note: print w/replies, xml ) Need Help??


in reply to Re: Complex Splitting
in thread Complex Splitting

I don't think it's a lot trickier. This oughta do it:
@array = grep defined, split /(\[.*?\])|/;
That is, if you split on a bracketed group, capture it. If you don't have a bracketed group, split on nothing. Then filter out where the capture didn't match.

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^3: Complex Splitting
by johngg (Canon) on Feb 06, 2007 at 18:29 UTC
    Yes, I regretted the word "lot" as soon as I'd posted, made it sound as if I'd sweated blood writing it. Although I like the simpler approach of your solution there is one problem with it; it doesn't get rid of the square brackets, which was required by the OP.

    Cheers,

    JohnGG

      Hasty reading on my part. Not capturing the brackets is as simple as leaving them outside the capturing parentheses:
      @array = grep defined, split /\[(.*?)\]|/;

      Caution: Contents may have been coded under pressure.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://598566]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2025-07-17 06:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.