Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
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? - 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?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2016-08-24 22:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The best thing I ever won in a lottery was:















    Results (351 votes). Check out past polls.