Proper use of regexprep
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
GEORGIOS BEKAS
el 22 de En. de 2018
Comentada: per isakson
el 17 de Dic. de 2018
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 comentarios
Guillaume
el 22 de En. de 2018
I don't understand the question. Your code already remove the consonants (assuming basic latin alphabet only). What more do you want?
per isakson
el 17 de Dic. de 2018
Your statement is lacking the square brackets. Try
s2 = regexprep(s1,'[qwrtpsdfghjklzxcvbnmQWRTPSDFGHKLZXCVBNM]','')
Respuesta aceptada
KL
el 22 de En. de 2018
Editada: KL
el 22 de En. de 2018
use the ^ operator. It should simply be,
s2 = regexprep(s1,'[^aeiou]','')
3 comentarios
KL
el 22 de En. de 2018
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!
Más respuestas (1)
the cyclist
el 22 de En. de 2018
Editada: the cyclist
el 22 de En. de 2018
Can you just do
s1 = s2;
after that? Or just
s1 = regexprep(s1,'qwrtpsdfghjklzxcvbnmQWRTPSDFGHKLZXCVBNM','');
directly, eliminating creating the intermediate variable s2?
0 comentarios
Ver también
Categorías
Más información sobre Characters and Strings en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!