Operator
Description
Example
(??expr)
Parse expr and include the resulting term
in the match expression.
When parsed, expr must correspond to a
complete, valid regular expression.
Dynamic expressions that use the backslash
escape character (\) require two
backslashes: one for the initial parsing of
expr, and one for the complete match.
'^(\d+)((??\\w{$1}))' determines
how many characters to match by reading
a digit at the beginning of the match. The
dynamic expression is enclosed in a
second set of parentheses so that the
resulting match is captured in a token. For
instance, matching '5XXXXX' captures
tokens for '5' and 'XXXXX'.
(??@cmd)
Execute the MATLAB command
represented by cmd, and include the output
returned by the command in the match
expression.
'(.{2,}).?(??@fliplr($1))' finds
palindromes that are at least four
characters long, such as 'abba'.
(?@cmd)
Execute the MATLAB command
represented by cmd, but discard any output
the command returns. (Helpful for
diagnosing regular expressions.)
'\w*?(\w)(?@disp($1))\1\w*'
matches words that include double letters
(such as pp), and displays intermediate
results.
Within dynamic expressions, use the following operators to define replacement terms.
Replacement Operator
Description
$& or $0
Portion of the input text that is currently a match
$`
Portion of the input text that precedes the current match
$'
Portion of the input text that follows the current match (use $'' to represent $')
$N
Nth token
$
Named token
${cmd}
Output returned when MATLAB executes the command, cmd
For more information, see “Dynamic Regular Expressions” on page 2-72.
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).
Regular Expressions
2-61
Précédent

- 111/1450

Suivant