A simple regex error

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

 Risposta accettata

Andrei Bobrov
Andrei Bobrov il 27 Mag 2013
use
tokens=regexp(str1,'peak\s*memory\s*use(\s)*d')

2 Commenti

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 il 27 Mag 2013
Modificato: Andrei Bobrov il 27 Mag 2013
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');

Accedi per commentare.

Più risposte (0)

Categorie

Prodotti

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by