MATLAB: Regexp help

commadecimalnumberregexpurlread

Hi, im trying to read in some numbers from some HTML:
'<br>1,020.32 mb<br>'
Im currently using regexp(string,'\d+','match'), how can i read in a number such as the one above that has a comma and a decimal point?

Best Answer

regexp(string, '(\d+,)*\d+(\.\d*)?', 'match')
The above is flexible enough to support any number of leading groups of digits and commas (including no leading groups). It is also flexible enough to support the possibility that the decimal point and following digits are not present -- so it supports the equivalent of your \d+ (plain integers without commas or decimal points). Furthermore it supports a trailing decimal point with no digits afterwards.