Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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

by Anonymous Monk
on Aug 17, 2000 at 03:10 UTC ( #28233=categorized answer: print w/replies, xml ) Need Help??

Q&A > regular expressions > How do I split a string on highly structured/nested data? - Answer 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;

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
[karlgoethebier]: good morning
[Corion]: Hi karlgoethebier!
[karlgoethebier]: anybody ever noticed the double bracket operator: while (<<>>) {print;}?

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2017-07-21 07:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (319 votes). Check out past polls.