Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Split using multiple conditions

by bart (Canon)
on Jun 11, 2005 at 11:31 UTC ( [id://465792]=note: print w/replies, xml ) Need Help??


in reply to Split using multiple conditions

That's an official FAQ: perlfaq 4: How can I split a [character] delimited string except when inside [character]?

Personally, I'd be inclined to use the dual approach: match the stuff between brackets, or nonspaces.

$_ = 'FDR [62.10060.051-F] [62.10051.381] [this includes spaces!] 0 1 +0'; @parts = /\[.*?\]|[^\[\]\ ]+/g; $\ = "\n"; print for @parts;

Yes it can be that compact. Result:

FDR [62.10060.051-F] [62.10051.381] [this includes spaces!] 0 1 0

A limitation is that you can't easily split on single spaces, thus returning empty strings as a section.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (7)
As of 2024-04-24 00:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found