Skip to content
Prev 325451 / 398503 Next

extract all numbers from a string

Hi all,

I have been beating my head against this problem for a bit, 
but I can't figure it out.

I have a series of strings of variable length, and each will 
have one or more numbers, of varying format.  E.g., I might 
have:


tmpstr = "The first number is: 32.  Another one is: 32.1. 
Here's a number in scientific format, 0.3523e10, and 
another, 0.3523e-10, and a negative, -313.1"

How could I get R to just give me a list of numerics 
containing the numbers therein?

Thanks very much to the regexp wizards!

Cheers,
Nick