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

hstr2 = '%%';<br />

expr = '()?..()?';<br />

regexp(hstr2, expr, 'match')<br />

ans =<br />

'%%'<br />

Zero or More — expr*<br />

The first regexp command looks for at least one occurrence of and finds<br />

it. The second command parses a different string for at least one and<br />

fails. The third command uses * toparsethesamelineforzeroormoreline<br />

breaks and this time succeeds.<br />

hstr1 = 'This string has line breaks';<br />

regexp(hstr1, '.*().*', 'match')<br />

ans =<br />

'This string has line breaks';<br />

hstr2 = 'This string has no line breaks';<br />

regexp(hstr2, '.*().*', 'match')<br />

ans =<br />

{}<br />

regexp(hstr2, '.*()*.*', 'match')<br />

ans =<br />

'This string has no line breaks';<br />

OneorMore—expr+<br />

Use + to verify that the HTML image source is not empty. This looks for one<br />

or more characters in the gif filename:<br />

hstr = '';<br />

expr = '

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

Saved successfully!

Ooh no, something went wrong!