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

    %% Case-Sensitive Match  
% Match letter case in all or part of an expression.   

%% 
% By default, |regexpi| performs case-insensitive matching. 
str = 'A character vector with UPPERCASE and lowercase text.';
expression = '\w*case';
matchStr = regexpi(str,expression,'match')  

%% 
% Use the |regexp| function with the same syntax as |regexpi| to perform
% case-sensitive matching. 
matchWithRegexp = regexp(str,expression,'match')  

%% 
% To disable case-sensitive matching for |regexp|, use the |'ignorecase'|
% option. 
matchWithIgnorecase = regexp(str,expression,'match','ignorecase')  

%% 
% For multiple expressions, enable and disable case-insensitive matching
% for selected expressions using the |(?i)| and |(?-i)| search flags. 
expression = {'(?-i)\w*case';...
              '(?i)\w*case'};
matchStr = regexp(str,expression,'match');
celldisp(matchStr)