23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Regular Expressions<br />

Match Token 1 Token 2<br />

andy<br />

y<br />

ted t d<br />

andrew<br />

rew<br />

andy<br />

y<br />

ted t d<br />

Only the highest level parentheses are used. For example, if the search<br />

pattern and(y|rew) finds the text andrew, token 1 is assigned the value rew.<br />

However, if the search pattern (and(y|rew)) is used, token 1 is assigned<br />

the value andrew.<br />

UsingTokens—Example2<br />

Use (expr) and \N to capture pairs of matching HTML tags (e.g., and<br />

) and the text between them. The expression used for this example is<br />

expr = '.*?';<br />

The first part of the expression, ’), and any characters that may precede the<br />

next opening bracket.<br />

The last part, '', matches all characters in the ending HTML tag. This<br />

tag is composed of the sequence , wheretag is whatever characters<br />

were captured as a token.<br />

hstr = 'Default';<br />

expr = '.*?';<br />

[mat tok] = regexp(hstr, expr, 'match', 'tokens');<br />

mat{:}<br />

ans =<br />

<br />

3-51

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!