Using regexp to extract data
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akira Agata
am 20 Feb. 2022
Do you want to detect "n + 3 digits" ?
If so, the regular expression will be 'n\d{3}'.
Antworten (1)
DGM
am 20 Feb. 2022
Bearbeitet: DGM
am 20 Feb. 2022
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)'))
If there is a restriction on the number of digits in the middle, you'll have to change the quantifier.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Data Type Identification finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!