Substitution systems in #MATLAB: p=@(c)1*(c==’0’)+2*(c==’1’); r={‘10’,’0’}; f=@(s)regexprep(s,’([01])’,’${r{p($1)}}’); f(f(f(‘1’))) #regexp