www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/CaptureSubstringsofMatchesUsingOrdinalTokensExample.m

    %% 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 |&lt;(\w+).*&gt;.*&lt;/\1&gt;| 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.  
% * |&lt;/\1&gt;| finds the end tag corresponding to the first token (indicated
% by |\1|). The end tag has the form _|&lt;/tagname&gt;|_.

%% 
% View the tokens and matching substrings. 
celldisp(tokens)  

%%  
celldisp(matches)