%% Hide Details when Displaying Complicated Patterns
% Use maskedPattern to display a variable in place of a complicated pattern expression.
% Build a pattern that matches simple arithmetic expressions composed of numbers and arithmetic operators.

mathSymbols = asManyOfPattern(digitsPattern | characterListPattern("+-*/="),1)

% Build a pattern that matches arithmetic expressions with whitespaces between characters using mathSymbols.

longExpressionPat = asManyOfPattern(mathSymbols + whitespacePattern) + mathSymbols

% The displayed pattern expression is long and difficult to read. Use maskedPattern to display the variable name, mathSymbols, in place of the pattern expression.

mathSymbols = maskedPattern(mathSymbols);
shortExpressionPat = asManyOfPattern(mathSymbols + whitespacePattern) + mathSymbols

% Create a string containing some arithmetic expressions, and then extract the pattern from the text.

txt = "What is the answer to 1 + 1? Oh, I know! 1 + 1 = 2!";
arithmetic = extract(txt,shortExpressionPat)

% Copyright 2020 The MathWorks, Inc.