Using regexp to extract data

조회 수: 3 (최근 30일)
M Abdelreheem
M Abdelreheem 2022년 2월 19일
편집: DGM 2022년 2월 20일
I am checking a code in which the following line is existed, as an example nNam= n111-y1 therefore I think this line reads all nNam which has this format (n1\d1$)|n1\d1-y,
nid = cellfun(@isempty,regexp(nNam,'(n1\d1$)|n1\d1-y'));
Now, I would like to read different nNam to be as an example nNam= n156, I searched for resources to get the corresponding regexp readible format but I did not find it. Could you help me with this?
Many thanks in advance
  댓글 수: 2
Akira Agata
Akira Agata 2022년 2월 20일
Do you want to detect "n + 3 digits" ?
If so, the regular expression will be 'n\d{3}'.
M Abdelreheem
M Abdelreheem 2022년 2월 20일
편집: M Abdelreheem 2022년 2월 20일
Thank you so much, it works well! but unfortunately, it detected all the lines started by a letter (n and m), is it applicable to detect points which start only with n1+2numbers+1 like (n1361) ?

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

답변 (1개)

DGM
DGM 2022년 2월 20일
편집: DGM 2022년 2월 20일
You haven't clearly stated what you want it to match and not match.
I'm going to assume that you want it to match "n1" followed by zero or more digits, with a trailing sequence consisting either of a single 1 or "1-y".
nNam = {'n111-y1','n156','n256','n1331'};
nid = cellfun('isempty',regexp(nNam,'n1\d*(1|1-y1)'))
nid = 1×4 logical array
0 1 1 0
If there is a restriction on the number of digits in the middle, you'll have to change the quantifier.

카테고리

Help CenterFile Exchange에서 Data Type Identification에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by