MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1
For more information, see “Dynamic Regular Expressions” on page 2-69.

Comments

The comment operator enables you to insert comments into your code to make it more
maintainable. The text of the comment is ignored by MATLAB when matching against the
input text.

Characters Description Example


(?#comment) Insert a comment in the regular
expression. The comment text is
ignored when matching the input.


'(?# Initial digit)\<\d\w+'
includes a comment, and matches
words that begin with a number.

Search Flags

Search flags modify the behavior for matching expressions.

Flag Description


(?-i) Match letter case (default for regexp and regexprep).


(?i) Do not match letter case (default for regexpi).


(?s) Match dot (.) in the pattern with any character (default).


(?-s) Match dot in the pattern with any character that is not a newline character.


(?-m) Match the ^ and $ metacharacters at the beginning and end of text
(default).


(?m) Match the ^ and $ metacharacters at the beginning and end of a line.


(?-x) Include space characters and comments when matching (default).


(?x) Ignore space characters and comments when matching. Use '\ ' and
'#' to match space and # characters.


The expression that the flag modifies can appear either after the parentheses, such as

(?i)\w*

or inside the parentheses and separated from the flag with a colon (:), such as

(?i:\w*)

The latter syntax allows you to change the behavior for part of a larger expression.

Regular Expressions
Free download pdf