FUNCTION REFERENCE

regexprep

Replace text using a regular expression.

Replace text using a regular expression.

Syntax

newStr = regexprep(str, expression, replace)

Syntax

newStr = regexprep(str, expression, replace, 'once')

Syntax

newStr = regexprep(str, expression, replace, 'ignorecase')

Syntax

newStr = regexprep(str, expression, replace, N)

In replace, $0 is the whole match, $1 to $9 are the tokens and $<name> is a

named token; $N past the last token stays as typed. \n, \t, \\ and \$

insert a newline, tab, backslash and dollar.

N replaces only the Nth match. A cell array of expressions applies each in

turn; replace may then be a cell array with one text per expression.

A cell array str gives a cell array of the same shape.

Example

regexprep('hello world', '(\w+) (\w+)', '$2 $1')   % 'world hello'

Differences from MATLAB: 'preservecase' and dynamic replacements ${...} are

not supported yet; the expression limits of regexp apply.

String inputs are supported with bounded two-dimensional storage.

Example

regexprep(["a1" "b2"],'[0-9]','X')

These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.