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

    %% Pattern Matching  
% Find words that start with |c|, end with |t|, and contain one or more
% vowels between them.   

%%  
str = 'bat cat can car COAT court cut ct CAT-scan';
expression = 'c[aeiou]+t';
startIndex = regexpi(str,expression) 

%%
% Values in |startIndex| indicate the index of the first character of each
% word that matches the regular expression. 

%%
% The regular expression |'c[aeiou]+t'| specifies this pattern: 
%  
% * |c| must be the first character.  
% * |c| must be followed by one of the characters inside the brackets, |[aeiou]|.  
% * The bracketed pattern must occur one or more times, as indicated by
% the |+| operator.  
% * |t| must be the last character, with no characters between the bracketed
% pattern and the |t|.