%% Match Patterns Optionally
% Use optionalPattern to designate a pattern as optional to match.
% Create txt as a string. Create a pattern, pat, that matches "foo" and will optionally match "bar" so long as it is preceded by "foo". Extract the pattern.

txt = "foo bar foobar";
pat = "foo" + optionalPattern("bar");
extract(txt,pat)

% Copyright 2020 The MathWorks, Inc.