%% Capture Substrings of Matches Using Ordinal Tokens
% Find the names of HTML tags by defining a token within a regular expression. Tokens are indicated with parentheses, ().

str = '<title>My Title</title><p>Here is some text.</p>';
expression = '<(\w+).*>.*</\1>';
[tokens,matches] = regexp(str,expression,'tokens','match');

% The regular expression <(\w+).*>.*</\1> specifies this pattern:
% <(\w+) finds an opening angle bracket followed by one or more alphanumeric or underscore characters. Enclosing \w+ in parentheses captures the name of the HTML tag in a token.
% .*> finds any number of additional characters, such as HTML attributes, and a closing angle bracket.
% </\1> finds the end tag corresponding to the first token (indicated by \1). The end tag has the form </tagname>.
%
% View the tokens and matching substrings.

celldisp(tokens)

%

celldisp(matches)

% Copyright 2012 The MathWorks, Inc.