%% Combine Patterns and Regular Expressions
% Use regexpPattern to specify patterns using regular expressions that can be used as inputs for text-searching functions.
% Find words that start with c, end with t, and contain one or more vowels in between.

txt = "bat cat can car coat court CUT ct CAT-scan";
expression = 'c[aeiou]+t';

% 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.
% Extract the pattern. Note, the words CUT and CAT do not match because they are uppercase.

pat = regexpPattern(expression);
extract(txt,pat)

% Patterns created using regexpPattern can be combined with other pattern functions to create more complicated patterns. Use whitespacePattern and lettersPattern to create a new pattern that also matches words after the regular expression matches, and then extract the new pattern.

pat = regexpPattern(expression) + whitespacePattern + lettersPattern;
extract(txt,pat)

% Copyright 2020 The MathWorks, Inc.