regexp help

31 visualizaciones (últimos 30 días)
Edward
Edward el 4 de Abr. de 2012
Comentada: Stephen23 el 11 de Jun. de 2021
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?
  1 comentario
Stephen23
Stephen23 el 28 de Feb. de 2015
Editada: Stephen23 el 28 de Feb. de 2015
For developing and checking regular expressions here is an interactive helper:

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 4 de Abr. de 2012
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.
  5 comentarios
Evangelos Stefanidis
Evangelos Stefanidis el 11 de Jun. de 2021
In my case I had the following string and I was interested in getting the number between -....mVPower-. That was my coding:
Sting='2021-06-08-Blank5-D150mm-R0mm-7LPM-0N2Shild-12.6mVPower-105ns-25ns-G600-C580-2Acc-60xInt-4VBins-slit10u-100Frames-NoIcorr-Polar-NoFilter.spe'
pattern1='(?<=\-)(\d+,)*\d+(\.\d*)?(?=mVPower\-)';
power=str2double(regexp(fname,pattern1,'match'));
Stephen23
Stephen23 el 11 de Jun. de 2021
S = '2021-06-08-Blank5-D150mm-R0mm-7LPM-0N2Shild-12.6mVPower-105ns-25ns-G600-C580-2Acc-60xInt-4VBins-slit10u-100Frames-NoIcorr-Polar-NoFilter.spe';
P = str2double(regexp(S,'\d+\.?\d*(?=mVPower)','match','once'))
P = 12.6000

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by