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

 Accepted Answer

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

More Answers (1)

regexprep(String, '[a-z]*', '')

4 Comments

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
Why touch your nose around the head instead of touching it directly?
It is a delicate question and I cannot give further details but I do need to know how to do it sorry.
You’re a funny guy xD.

Sign in to comment.

Categories

Community Treasure Hunt

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

Start Hunting!