Remove parenthesis and the contents inside from a string
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Yuzhen Lu
am 7 Jan. 2021
Kommentiert: Stephen23
am 9 Mär. 2023
Is there a neat way to remove a parenthesis and the contents inside from a string. For example the string
A = 'abc (ABC)'
% how to extract 'abc' from A, get rid of ' (ABC)' including the leading whitespace?
One cumbersome solution is:
temp = strsplit(A,'(');
B = strtrim(temp(1));
0 Kommentare
Akzeptierte Antwort
Stephen23
am 7 Jan. 2021
A = 'abc (ABC)';
B = regexp(A,'^\w+','once','match')
5 Kommentare
Stephen23
am 9 Mär. 2023
"I mean to extract the only the characters that exist in brackets without the others."
A = 'abc (ABC)';
B = regexprep(A,{'.*\(','\).*'},'')
Weitere Antworten (1)
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!