Help with Regexp
10 views (last 30 days)
So i have a table of numbers read in using fread from a .dat file:
0 0 3.51563 50 35.1563
0.094 10 3.47656 50 34.7656
Including some decimals and some integers, I've tried using:
to get each of these numbers into an individual element of array numdata but for some reason regexp reads in the whole line of numbers into one element rather than each one individually. Thanks for any help
Walter Roberson on 20 Apr 2012
The dot matches everything. You need \. to match a period.
numdata = regexp(data, '-?\d+(\.\d+)?', 'match');
This assumes that if the decimal point is present then it is always followed by at least one digit, and it assumes that there is always at least one digit before the decimal point. In particular,
are examples of numeric formats that the expression would not match.
The expression always will not match numbers in exponential format.