MATLAB: How to replace multiple strings with another string

stringsstrrep

Hello! I am trying to replace multiple words in a string with a single word. For example the sentence would be Hello girl and cat and I want to change it to Hello boy and boy. I've tried to format it as s being Hello girl and cat and then strrep (s, 'girl' 'cat', 'boy')
Thank you!

Best Answer

str='Hello girl and cat'
out=regexprep(str,'girl|cat','boy')
%If you want to use strrep
str='Hello girl and cat'
out=strrep(str,'girl','boy')
out=strrep(out,'cat','boy')