Extracting number from a string of varying format

Hi,

Here is the problem: In the workflow, the operator will need to enter a sample holder id number.  I know where in the data file it will be, but the actual text can be quite variable given the number of operators.

The stings may be but not limited to:

"holder 31"

"pan 3"

"31"

"sample holder 31"

and various misspellings of words. But all I am interested in is the 31.

What is the simplest way just to extract the number from variable text string?

Andy

 

Some additional questions one needs to think about: Is the sample holder ID always just a number without characters included? Can the ID be followed by further words or characters? Can the string before the ID contain numbers? If the answer to all of these questions is no, then the following function should do the trick:

Function readID(string input)
    string scrap, num
    SplitString /E="([[:alpha:]]*) *([[:digit:]]+)" input, scrap, num
    return str2num(num)
End
print readID("holder 31")
  31
print readID("31")
  31
print readID("sample holder 31")
  31