23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Regular Expressions<br />

Remove the grouping, and the {2,} now applies only to [aeiou]. The<br />

command is entirely different now as it looks for a nonvowel followed by at<br />

least two consecutive vowels:<br />

expr = '[^aeiou][aeiou]{2,}';<br />

[mat ix1 ix2] = regexp(pstr, expr, 'match', 'start', 'end')<br />

mat =<br />

'see'<br />

ix1 =<br />

18<br />

ix2 =<br />

20<br />

Atomic Grouping — (?>expr)<br />

Alternative Match — expr1|expr2<br />

Use p 1<br />

|p 2<br />

to pick out words in the string that start with let or tel:<br />

regexpi(pstr, '(let|tel)\w+', 'match')<br />

ans =<br />

'lets' 'telegram'<br />

Nonmatching Operators<br />

The comment operator enables you to insert commentsintoyourcodetomake<br />

it more maintainable. The text of the comment is ignored by <strong>MATLAB</strong> when<br />

matching against the input string.<br />

Operator<br />

(?#comment)<br />

Usage<br />

Insert a comment into the expression. Comments are<br />

ignored in matching.<br />

Including Comments — (?#expr)<br />

Use (?#expr) to add a comment to this expression that matches capitalized<br />

words in pstr. Comments are ignored in the process of finding a match:<br />

3-39

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

Saved successfully!

Ooh no, something went wrong!