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

Stephen23
Stephen23 2015년 2월 28일
편집: Stephen23 2015년 2월 28일
For developing and checking regular expressions here is an interactive helper:

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2012년 4월 4일

3 개 추천

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

Edward
Edward 2012년 4월 4일
Thankyou! is there any chance you can explain what that expression means? im quite new to regexp
Ashish Uthama
Ashish Uthama 2012년 4월 5일
Edward, this might help you get started: http://www.mathworks.com/help/techdoc/matlab_prog/f0-42649.html#f0-42723
Breakdown:
(\d+,) -- One or more digit(s) followed by a comma
* -- zero or more instances of stuff within ()
\d+ -- One or more digit(s)
(\.\d*)-- A . (the \ is to 'escape it' since just using a . has a different meaning) followed by zero or more digit(s)
? -- zero or one instance of the stuff within ()
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'));
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

질문:

2012년 4월 4일

댓글:

2021년 6월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by