This question is related to Extract first & last characters of macro argument?.
It seems that if, besides getting first and last tokens, one wants to accumulate the rest of the tokens, the solution is nontrivial. My solution appears convoluted. I wonder if David Carlisle can instantly pull a neater one out of his pocket. Full expansion of tokens should be avoided because they may contain undefined controls.
\documentclass{article}
\makeatletter
\usepackage{catoptions}
\def\fl#1{\fl@i#1\@nil\@nil\@nnil}
\def\fl@i#1#2#3\@nnil{%
\def\rest{}\def\last{}%
\edef\first{\ifstrcmpTF{#1}\@nil{}{\unexpanded{#1}}}%
\edef\reserved@b{\unexpanded{#3}}%
\ifcsemptyTF\reserved@b{%
\edef\last{\ifstrcmpTF{#2}\@nil{}{\unexpanded{#2}}}%
}{%
\ifcseqTF\reserved@b\@nnil{%
\edef\last{\ifstrcmpTF{#2}\@nil{}{\unexpanded{#2}}}%
}{%
\edef\last{\unexpanded{#2}}%
\fl@ii#3\@nnil
}%
}%
\ifx\last\rest\def\rest{}\fi
}
\def\fl@ii#1#2#3\@nnil{%
\ifstrcmpTF{#1}\@nil{}{%
\ifstrcmpTF{#2}\@nil{%
\edef\rest{\expandcsonce\last\expandcsonce\rest}%
\edef\last{\unexpanded{#1}}%
}{%
\edef\rest{\expandcsonce\rest\unexpanded{#1}}%
\fl@ii#2#3\@nnil
}%
}%
}
\def\x{\string\x}
\def\y#1{\fl{#1}\immediate\write20{Given token
[\iflacus#1\dolacus empty/null\else#1\fi]
^^J[\first][\last][\rest]}
}
\immediate\write20{[first][last][rest]}
\y{}
\y{\x}
\y{1\x2}
\y{123}
\y{1234\x}
\begin{document}
x
\end{document}

@egreg), you probably only voted those answers up. To accept an answer (only one accepted answer per question), click on the green(?) checkmark below the arrows used for voting. By the way, here, feel free to accept a non-LaTeX3 answer if those were more helpful. – Bruno Le Floch Feb 04 '12 at 23:16