Just for fun, a fully expandable version that doesn't need any packages. Again, the argument to \inverthand is detokenized. You can set the letters recognized by altering the line
\edef\herda@invertletters{\detokenize{mspz}}
and change the symbols which are also considered as part of the numbers by altering the line
\edef\herda@alsodigit{\detokenize{*~?}}
So here is the complete code:
\documentclass[]{article}
\makeatletter
\edef\herda@alsodigit{\detokenize{*~?}}
\edef\herda@invertletters{\detokenize{mspz}}
\def\herda@qstop{\herda@qstop}
\long\def\herda@fi@firstoftwo\fi\@secondoftwo#1#2{\fi#1}
\long\def\herda@fi@gobble\fi\@firstofone#1{\fi}
\newcommand\herda@ifdigit[1]%>>=
{%
\ifnum1<1\noexpand#1 \herda@fi@firstoftwo\fi\@secondoftwo
}%=<<
% we can make a few assumptions here which help to keep this tokenin
% implementation simple:
% 1. argument 1 will be not empty and a single token
% 2. argument 2 will contain no groups
\long\def\herda@iftokenin@true\fi%>>=
\herda@iftokenin@#1\herda@qstop\@secondoftwo#2#3{\fi#2}%=<<
\newcommand\herda@iftokenin@[2]%>>=
{%
\ifx\herda@qstop#2\herda@fi@gobble\fi
\@firstofone
{%
\ifx#1#2%
\herda@iftokenin@true
\fi
\herda@iftokenin@#1%
}%
}%=<<
\newcommand\herda@iftokenin[2]%>>=
{%
\herda@iftokenin@#1#2\herda@qstop\@secondoftwo
}%=<<
\newcommand\herda@invert%>>=
{%
\herda@invert@{}%
}%=<<
\long\edef\herda@invert@#1#2%>>=
{%
\unexpanded{\ifx\herda@qstop}#2%
\unexpanded{\herda@fi@firstoftwo\fi\@secondoftwo}%
{#1}%
{%
\noexpand\herda@ifdigit{#2}
{\noexpand\herda@invert@{#1#2}}
{%
\noexpand\herda@iftokenin#2{\herda@alsodigit}%
{\noexpand\herda@invert@{#1#2}}
{%
\noexpand\herda@iftokenin#2{\herda@invertletters}%
{#2#1\noexpand\herda@invert@{}}
{#1#2\noexpand\herda@invert@{}}%
}%
}%
}%
}%=<<
\newcommand\inverthand[1]%>>=
{%
\expandafter\herda@invert\detokenize{#1}\herda@qstop
}%=<<
\begin{document}
fully expandable:\par
\edef\foo{\inverthand{123p456789m333s22z}}\texttt{\meaning\foo}
\inverthand{1~23p456789m333s22z}
\inverthand{1*23p456789m333s22z}
\inverthand{1?23p456789m333s22z}
\inverthand{1?23d456789m333s22z}
\end{document}
