I would like to extract the leading number and subsequent text from a string. I have an idea of using the xstring package to gobble characters from the right until I end up with a number or an empty string, but wondering if there is an easier way to do it. The leading number is all the text up until the first character that is not a digit, period, or a plus and minus sign.
Don't really need to worry about error cases such as:
- an additional
+,-within the number - more digits after first non-numerical digit
So, I should get the following output with the definitions of \ExtractLeadingNumber and \ExtractTralingNonDigits completed:

Code:
\documentclass[border=2pt]{standalone}
\usepackage{booktabs}
\newcommand{\ExtractLeadingNumber}[1]{#1}%
\newcommand{\ExtractTralingNonDigits}[1]{#1}%
% ignore #2 and #3 as those are only needed to produce the desired output
\newcommand{\Test}[3]{#1&\ExtractLeadingNumber{#1}&\ExtractTralingNonDigits{#1}\}%
%\newcommand{\Test}[3]{#1\}% This produces desired output
\begin{document}
\begin{tabular}{l r r r}
& &Number &Non-Digits\
\midrule
Decimal:
&\Test{ 1.01abc}{ 1.01}{abc}
&\Test{+2.01abc}{+2.01}{abc}
&\Test{-3.01abc}{-3.01}{abc}
\midrule
Integer:
&\Test{ abc}{ }{abc}
&\Test{ 5abc}{ 5}{abc}
&\Test{+6abc}{+6}{abc}
&\Test{-7abc}{-7}{abc}
\midrule
Floating Point:
&\Test{ 5.34abc}{ 5.34}{abc}
&\Test{+6.34abc}{+6.34}{abc}
&\Test{-7.34abc}{-7.34}{abc}
\midrule
Number Only:
&\Test{3}{3}{}
&\Test{3.2}{3.2}{}
&\Test{-5.1}{-5.1}{}
&\Test{+5.1}{+5.1}{}
\midrule
No Digits:
&\Test{abc}{}{abc}
\midrule
Formatted Text:
&\Test{ 8$abc_1$}{ 8}{$abc_1$}
&\Test{-8.2$abc_1$}{-8.2}{$abc_1$}
&\Test{+$abc_1$}{+}{$abc_1$}
&\Test{$abc_1$}{}{$abc_1$}% no digits
\end{tabular}
\end{document}

xstring, or are you aiming for plain tex? – cmhughes Nov 18 '11 at 06:21