I'm not sure what you want...you say you want the printables,
without spaces, but then you say you only want "foo" which
excludes bar (printable chars) and the colon. You might try one of
echo substitute(':foo^[bar', '[^[:graph:]]\+', '', 'g')
echo substitute(':foo^[bar', '[^[:print:]]\+', '', 'g')
echo matchstr(':foo^[bar', '[[:graph:]]\+')
or some permutation thereof. You may want to read up at
:help substitute()
:h [:graph:]
:h [:print:]
If you give a clearer list of inputs and desired outputs, it
might be possible to give a more precise answer.
-tim