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

 Réponse acceptée

Andrea Cappannini
Andrea Cappannini le 22 Juil 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

Plus de réponses (1)

madhan ravi
madhan ravi le 20 Juil 2020
regexprep(String, '[a-z]*', '')

4 commentaires

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 le 20 Juil 2020
Why touch your nose around the head instead of touching it directly?
Andrea Cappannini
Andrea Cappannini le 20 Juil 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 le 20 Juil 2020
You’re a funny guy xD.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by