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
Jan 2017 年 6 月 21 日
Fine. What is your question?
elisa ewin
elisa ewin 2017 年 6 月 22 日
sorry, now I re-write the question
Jan
Jan 2017 年 6 月 22 日
編集済み: Jan 2017 年 6 月 22 日
Weather booming Chilli Relax https://t.co/pwp00Ndw3d
This looks strange. It reminds me to Google: Britney Spears Instagram account used by hackers.
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
Andrei Bobrov 2017 年 6 月 22 日

2 投票

regexprep(b,'[$#@]|\<https:/+\S*\>','')

8 件のコメント

elisa ewin
elisa ewin 2017 年 6 月 22 日
if I want delete all special characters and not only (@,#,$), how can I modify this expression?
Jan
Jan 2017 年 6 月 22 日
@Andrei: [$#@]|\<https:/+\S*\> ??? Looks like a rocket. +1
Stephen23
Stephen23 2017 年 6 月 22 日
@elisa ewin: what is a "special character" ?
elisa ewin
elisa ewin 2017 年 6 月 22 日
all characters that are not letters or numbers: I know them like special characters
Stephen23
Stephen23 2017 年 6 月 22 日
編集済み: Stephen23 2017 年 6 月 22 日
@elisa ewin: Your explanation contradicts your examples: if "special characters" are "not letters or numbers", then why do your examples still contain space characters in the output? Following your definition of "special characters" the space characters should have been removed as well: "I want to delete from these expressions all the characters like @,#,$ and...": clearly your original question and your definition of "special characters" requires no space characters in the output.
So, is a space character special? What about a comma? What about a newline? Is a non-breaking space special? What about an underscore? Is a tab character special?
Jan
Jan 2017 年 6 月 22 日
@Elisa: Do you mean:
  • split string at spaces to words
  • delete all words starting with 'https://' or all words containing '/'
  • remove all special characters identified by: ~isstrprop(S, 'alphanum')
elisa ewin
elisa ewin 2017 年 6 月 22 日
yes
Andrei Bobrov
Andrei Bobrov 2017 年 6 月 22 日
編集済み: Andrei Bobrov 2017 年 6 月 22 日
Hi Jan! Yes! "Russian rocket". :)
regexprep(b,'\<[^A-Za-z \?\,]|https:/+\S*\>','')

サインインしてコメントする。

その他の回答 (1 件)

Jan
Jan 2017 年 6 月 22 日
編集済み: Jan 2017 年 6 月 22 日

0 投票

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

カテゴリ

質問済み:

2017 年 6 月 21 日

編集済み:

2017 年 6 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by