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 ExchangeVariables についてさらに検索

製品

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by