www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/FindPatternsinSingleStringsExample.m
%% Find Patterns in Text % 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 = regexp(str,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|. %% % Values in |startIndex| indicate the index of the first character of each % word that matches the regular expression. The matching word |cat| starts % at index 5, and |coat| starts at index 17. The words |CUT| and |CAT| do % not match because they are uppercase.