www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/PreserveCaseinOriginalStringExample.m

    %% Preserve Case in Original Text 
% Ignore letter case in the regular expression when finding matches, but
% mimic the letter case of the original text when updating.   

%%  
str = 'My flowers may bloom in May';
expression = 'M(\w+)y';
replace = 'April';

newStr = regexprep(str,expression,replace,'preservecase')