2015-02-09 115 views
0

我试图用函数regexprep替换字符串中的元音与另一个字符。例如,在Matlab中使用regexprep替换字符

content = regexprep('refrigerator', '[aeiou]', '!') 

content = r!fr!g!r!t!r 

然而,当我试图代替字符数组的使用一个字符串变量,它似乎不工作:

allowedChar = 'aeiou'; 
content = regexprep('refrigerator', allowedChar, '!') 

content = refrigerator 

我该如何解决这个问题?

回答

3

您忘记了allowedChar中的[]个字符。它应该是:

allowedChar = '[aeiou]'; 
content = regexprep('refrigerator', allowedChar, '!') 
+0

是啊,那是相当多了! – rayryeng 2015-02-09 08:22:45

0

对于这样一个简单的替换你可以使用ismember代替regexprep

content(ismember(content, 'aeiou')) = '!';