Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Answer: How do I split a string on highly structured/nested data?

( #28233=categorized answer: print w/ replies, xml ) Need Help??

Q&A > regular expressions > How do I split a string on highly structured/nested data? contributed by Anonymous Monk

This should work more reliably in case there are repeated strings:
$_ = "a,b,op2(c,d),(e),(f),(f,g),op3(e,op4(f,g))\n"; print; ($re=$_)=~s/((\()|(\))|.)/$2\Q$1\E$3/gs; @$ = (eval{/$re/}); die $@ if $@=~/unmatched/; $re = join'|',map{quotemeta}@$; print join"\n",/((?:$re|[^,])+)/g;

Comment on Answer: How do I split a string on highly structured/nested data?
Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2016-02-13 17:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?





    Results (442 votes), past polls