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.

3 Basic Program Components<br />

regexp(pstr, '(?# Match words in caps)[A-Z]\w+', 'match')<br />

ans =<br />

'Marge' 'Norah' 'Sharon'<br />

Positional Operators<br />

Positional operators in an expression match parts of the input string not by<br />

content, but by where they occur in the string (e.g., the first N characters in<br />

the string).<br />

Operator<br />

^expr<br />

expr$<br />

\<br />

\<br />

Usage<br />

Match expr if it occurs at the beginning of the input<br />

string.<br />

Match expr if it occurs at the end of the input string.<br />

Match expr when it occurs at the beginning of a word.<br />

Match expr when it occurs at the end of a word.<br />

Match expr when it represents the entire word.<br />

Start and End of String Match — ^expr, expr$<br />

Use ^expr to match words starting with the letter m or M only when it begins<br />

the string, and expr$ to match words ending with m or M only when it ends<br />

the string:<br />

regexpi(pstr, '^m\w*|\w*m$', 'match')<br />

ans =<br />

'Marge' 'telegram'<br />

Start and End of Word Match — \<br />

Use \

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

Saved successfully!

Ooh no, something went wrong!