Dynamic ExpressionsDynamic expressions allow you to execute a MATLAB command or a regular expression to
determine the text to match.The parentheses that enclose dynamic expressions do not create a capturing group.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 OperatorDescription
$& 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
$<name> Named token
${cmd} Output returned when MATLAB executes the command, cmd2 Program Components