$input = '(E,(A,B),(C,(X,Y,Z),D),F)'; $parsed = ['E,',['A,B'],',',['C,',['X,Y,Z'],',D'],',F']; $filtered = ['E,',',',',F']; $output = '(E,F)';