Extracting a number from a sentence string

I am trying to extract numbers from a sentence string through a function that does not know the exact placement or how many numbers are in the string.
for example my input would be
a='my weight is between 200 and 250 lbs'
or it could be
a='my weight is 200 lbs'
the weight will always be before "lbs", but the length of weight string is unknown.
I am having trouble using the sscanf function to make a universal code to extract the numbers from a string. Any help is greatly appreciated.

Answers (1)

A start
>> a='my weight is between 200 and 250 lbs'
a =
my weight is between 200 and 250 lbs
>> cac = regexp( a, '\d++', 'match' )
cac =
'200' '250'
Warning: This will not match '1.2E-003', not even '-4' :-(

Tags

Asked:

on 8 Feb 2015

Edited:

on 8 Feb 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!