Hi:
I have a simple expression and trying to do a regexp, but it fails. I do not understand why the first regexp fails while the second one succeeds.:
>> str1='peak memory used 124.63 megabytes';
>> tokens=regexp(str1,'peak\s*memory\s*use(\s)*\d')
tokens =
[]
>> tokens=regexp(str1,'peak\s*memory\s*use(\s)*')
tokens =
1

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2013년 5월 27일

0 개 추천

use
tokens=regexp(str1,'peak\s*memory\s*use(\s)*d')

댓글 수: 2

Bugaboo
Bugaboo 2013년 5월 27일
Actually, this works. But I always thought that \d is to match a digit. But it looks like it is "d", instead of "/d". I am bit confused about that. Furthermore, if I change the str1 to following, then the regexp still works where it should not.
>> str1='peak memory used d 124.63 megabytes';
>> tokens=regexp(str1,'peak\s*memory\s*use(\s)*d')
tokens =
1
>> str1='peak memory used r 124.63 megabytes';
>> tokens=regexp(str1,'peak\s*memory\s*use(\s)*d')
tokens =
1
What I want is to find a pattern in a textfile which has been read to buffer and I am looking for a number after (with possibly some whitespaces after) the phrase "peak memory used".
Thanks
Andrei Bobrov
Andrei Bobrov 2013년 5월 27일
편집: Andrei Bobrov 2013년 5월 27일
Hi Bugaboo!
Please try this is code and read about Regular expression in regexp:
str1='peak memory used d 124.63 megabytes';
tokens=regexp(str1,'(?<=peak memory used\s*\w*\s*)\d*\.\d*','match');

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

추가 답변 (0개)

카테고리

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

제품

태그

Community Treasure Hunt

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

Start Hunting!

Translated by