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 />

Operator<br />

Usage<br />

. Any single character, including white space<br />

[c 1<br />

c 2<br />

c 3<br />

] Any character contained within the brackets: c 1<br />

or c 2<br />

or c 3<br />

[^c 1<br />

c 2<br />

c 3<br />

]<br />

Any character not contained within the brackets:<br />

anything but c 1<br />

or c 2<br />

or c 3<br />

[c 1<br />

-c 2<br />

] Any character in the range of c 1<br />

through c 2<br />

\s Any white-space character; equivalent to [<br />

\f\n\r\t\v]<br />

\S Any non-whitespace character; equivalent to [^<br />

\f\n\r\t\v]<br />

\w Any alphabetic, numeric, or underscore character;<br />

equivalent to [a-zA-Z_0-9]. (This does not apply to<br />

non-English character sets).<br />

\W Any character that is not alphabetic, numeric, or<br />

underscore; equivalent to [^a-zA-Z_0-9]. (Trueonly<br />

for English character sets).<br />

\d Any numeric digit; equivalent to [0-9]<br />

\D Any nondigit character; equivalent to [^0-9]<br />

The following examples demonstrate how to use the character classes listed<br />

above. See the regexp reference page for help with syntax. Most of these<br />

examples use the following string:<br />

str = 'The rain in Spain falls mainly on the plain.';<br />

Any Character — .<br />

Use '..ain' in an expression to match a sequence of five characters ending<br />

in 'ain'. Notethat. matches white-space characters as well:<br />

regexp(str, '..ain')<br />

ans =<br />

4 13 24 39<br />

3-34

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

Saved successfully!

Ooh no, something went wrong!