Proper use of regexprep
조회 수: 2 (최근 30일)
이전 댓글 표시
I want to remove the consonants of a string, using regexprep. How can I modify the initial string s1 with a string s2?
s2 = regexprep(s1,'qwrtpsdfghjklzxcvbnmQWRTPSDFGHKLZXCVBNM','')
댓글 수: 2
Guillaume
2018년 1월 22일
I don't understand the question. Your code already remove the consonants (assuming basic latin alphabet only). What more do you want?
per isakson
2018년 12월 17일
Your statement is lacking the square brackets. Try
s2 = regexprep(s1,'[qwrtpsdfghjklzxcvbnmQWRTPSDFGHKLZXCVBNM]','')
채택된 답변
KL
2018년 1월 22일
편집: KL
2018년 1월 22일
use the ^ operator. It should simply be,
s2 = regexprep(s1,'[^aeiou]','')
댓글 수: 3
KL
2018년 1월 22일
it removes every character except what you mention inside the square brackets following ^ sign.
s2 = regexprep(s1,'[^aeiouA-Z]','') %ignores capital letters (A-Z)
s2 = regexprep(s1,'[^aeiouA-Z\s]','') %ignores white spaces as well
I gave you the link to documentation. It explains much more and guess what, even with examples!
추가 답변 (1개)
the cyclist
2018년 1월 22일
편집: the cyclist
2018년 1월 22일
Can you just do
s1 = s2;
after that? Or just
s1 = regexprep(s1,'qwrtpsdfghjklzxcvbnmQWRTPSDFGHKLZXCVBNM','');
directly, eliminating creating the intermediate variable s2?
댓글 수: 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!