%% Capture Substrings of Matches Using Named Tokens
% Parse dates that can appear with either the day or the month first, in these forms: mm/dd/yyyy or dd-mm-yyyy. Use named tokens to identify each part of the date.

str = '01/11/2000  20-02-2020  03/30/2000  16-04-2020';
expression = ['(?<month>\d+)/(?<day>\d+)/(?<year>\d+)|'...
              '(?<day>\d+)-(?<month>\d+)-(?<year>\d+)'];
tokenNames = regexp(str,expression,'names');

% The regular expression specifies this pattern:
% (?<name>\d+) finds one or more numeric digits and assigns the result to the token indicated by name.
% | is the logical or operator, which indicates that there are two possible patterns for dates. In the first pattern, slashes (/) separate the tokens. In the second pattern, hyphens (-) separate the tokens.
%
% View the named tokens.

for k = 1:length(tokenNames)
   disp(tokenNames(k))
end

% Copyright 2015 The MathWorks, Inc.