Removing multiple substrings in a string

I have a string like this
String = 'AAAAAAAAAbbbbbbbbbbbbbbbbCCCCCCCCCCCCCCCCCddddddddddddddddddEEEEEEEEEEEE';
% I want to remove all the lowercase letters so I need some indexes to do it
[Start,End]=regexp(String,'[a-z]{1,}');
%Here it comes the problem
I do not know how to remove multiple substring from the same string. eraseBetween provide a way to index a substring but how to remove multiple ones?
Thank you in advance

 Respuesta aceptada

Andrea Cappannini
Andrea Cappannini el 22 de Jul. de 2020
The answer I was searching for was:
x = 'AAAAAAAAAAAaaaaaaaaaaaTTTTTTTTTTTTTTTTsssssssssssTTTTTTTTTT'; % input
y = x; % initiallize result
[Start, End] = regexp(x, '[a-z]{1,}');
for k = numel(Start):-1:1 % note: from last to first
y(Start(k):End(k)) = []; % remove section
end

Más respuestas (1)

madhan ravi
madhan ravi el 20 de Jul. de 2020
regexprep(String, '[a-z]*', '')

4 comentarios

I expressed in wrong way what I need Sorry. Let us suppose that I have the indexes of the substrings namely I now where the substrings start and end but. By these indexes I have to eliminate these substrings contained in the original substring. E.g. :
% I find the substrings position by regexp
[Start,End]= regexp(String,'[a-z]{1,}');
%I only know these positions and I have String that is very long and very difficult to analyze
%By these positions that are vector of numbers, I want to eliminate the substring that locates
%In those positions.
I hope I was clearer now. My fault sorry
madhan ravi
madhan ravi el 20 de Jul. de 2020
Why touch your nose around the head instead of touching it directly?
Andrea Cappannini
Andrea Cappannini el 20 de Jul. de 2020
It is a delicate question and I cannot give further details but I do need to know how to do it sorry.
madhan ravi
madhan ravi el 20 de Jul. de 2020
You’re a funny guy xD.

Iniciar sesión para comentar.

Categorías

Más información sobre Characters and Strings en Centro de ayuda y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by