delete elements from a cell array
1 回表示 (過去 30 日間)
古いコメントを表示
Hi!
I have a cell array b (attached); in each cell of b I have an expression like this: 'Weather booming Chilli Relax https://t.co/pwp00Ndw3d' or expressions with @,#,$. I want to delete from these expressions all the characters like @,#,$ and the links like https://t.co/pwp00Ndw3d.
Example: if I have 'Weather booming @Chilli Relax# https://t.co/pwp00Ndw3d', I will want it becames 'Weather booming Chill Relax'
Can you help me? thanks
3 件のコメント
Jan
2017 年 6 月 22 日
編集済み: Jan
2017 年 6 月 22 日
Weather booming Chilli Relax https://t.co/pwp00Ndw3d
Perhaps I'm too distrustful, but I've modified the URL slightly to be sure. This does not change the core of the question or the answer. Sorry, these are hard times in the world wide web. Please do not take this personally.
採用された回答
Andrei Bobrov
2017 年 6 月 22 日
regexprep(b,'[$#@]|\<https:/+\S*\>','')
8 件のコメント
Andrei Bobrov
2017 年 6 月 22 日
編集済み: Andrei Bobrov
2017 年 6 月 22 日
Hi Jan! Yes! "Russian rocket". :)
regexprep(b,'\<[^A-Za-z \?\,]|https:/+\S*\>','')
その他の回答 (1 件)
Jan
2017 年 6 月 22 日
編集済み: Jan
2017 年 6 月 22 日
S = 'Weather booming Chilli Relax https://t.co/pwp00Ndw3d';
C = strsplit(S, ' ');
C(contains(C, '/')) = []; % Or how you identify a link
for iC = 1:numel(C)
aC = C{iC};
C{iC} = aC(isstrprop(aC, 'alphanum'));
end
Result = sprintf('%s ', C{:});
Result(end) = [];
The command contains was introduced in R2016b. If you have an older version, use:
function Tf = contains(C, Patterm)
Tf = ~cellfun('isempty', strfind(C, Pattern));
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!