finding a string with parentheses using regexp
15 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
wesso Dadoyan
am 22 Jun. 2016
Bearbeitet: Stephen23
am 23 Jun. 2016
A={'5123(P)';'5123 ESP'} how can i search A to find the cell that has the '(P)' string?
find(~cellfun(@isempty,regexp(A,'(P)')));
is giving 1 & 2 as answer which is not correct since it should be 1 only
0 Kommentare
Akzeptierte Antwort
Stephen23
am 22 Jun. 2016
Bearbeitet: Stephen23
am 23 Jun. 2016
find(~cellfun(@isempty,regexp(A,'\(P\)')));
Explanation: parentheses are special characters in regular expressions, and need to be escaped to be treated as literal parentheses. Of course the documentation is the best place to learn how to to use regular expressions properly:
Alternatively you could simply use strfind instead of regexp:
find(~cellfun(@isempty,strfind(A,'(P)')))
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Characters and Strings 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!