MATLAB: Swapping Letters Using Regular Expression

character arrayMATLABregexpregular expressionswap letterstext;

I want to take a character array, find the first vowel and move it to the end. Some examples
  • 'Fred' –> 'Frde'
  • 'Replace' –> 'Rplacee'
  • 'Cannot' –> 'Cnnota'
Is there a regular expression that will accomplish this with a single call to regexp?
Thank you

Best Answer

>> text = {'Fred', 'Replace', 'Cannot'};
>> regexprep(text, '([^aeiou]*)([aeiou])(.*)', '$1$3$2')
ans =
1×3 cell array
{'Frde'} {'Rplacee'} {'Cnnota'}