%% Display Specified Pattern Names
% Use maskedPattern to display a specified name for a complicated pattern expression.
% Build two patterns: one that matches words that begin and end with the letter D, and one that matches words that begin and end with the letter R.

dWordsPat = letterBoundary + caseInsensitivePattern("d" + lettersPattern + "d") + letterBoundary;
rWordsPat = letterBoundary + caseInsensitivePattern("r" + lettersPattern + "r") + letterBoundary;

% Use maskedPattern to display a specified name in place of the pattern expressions. Build a pattern using the masked patterns that find words that start and end with D followed by a word that starts and ends with R.

dWordsPat = maskedPattern(dWordsPat,"Words that start and end with D");
rWordsPat = maskedPattern(rWordsPat,"Words that start and end with R");
dAndRWordsPat = dWordsPat + whitespacePattern + rWordsPat

% Create a string, and then extract the pattern from the text.

txt = "Dad, look at the divided river!";
words = extract(txt,dAndRWordsPat)

% Copyright 2020 The MathWorks, Inc.