%% Perform Case-Insensitive Matches
% Find both uppercase and lowercase instances of a word.
% By default, regexp performs case-sensitive matching.

str = 'A character vector with UPPERCASE and lowercase text.';
expression = '\w*case';
matchStr = regexp(str,expression,'match')

% The regular expression specifies that the character vector:
% Begins with any number of alphanumeric or underscore characters, \w*.
% Ends with the literal text case.
%
% The regexpi function uses the same syntax as regexp, but performs case-insensitive matching.

matchWithRegexpi = regexpi(str,expression,'match')

%
% Alternatively, disable case-sensitive matching for regexp using the 'ignorecase' option.

matchWithIgnorecase = regexp(str,expression,'match','ignorecase')

%
% For multiple expressions, disable case-sensitive matching for selected expressions using the (?i) search flag.

expression = {'(?-i)\w*case';...
              '(?i)\w*case'};
matchStr = regexp(str,expression,'match');
celldisp(matchStr)

% Copyright 2012 The MathWorks, Inc.