Navigation

Operators and Keywords

Function List:

C++ API

: outstr = regexprep (string, pat, repstr)
: outstr = regexprep (string, pat, repstr, "opt1", …)

Replace occurrences of pattern pat in string with repstr.

The pattern is a regular expression as documented for regexp. See ‘regexp’.

The replacement string may contain $i, which substitutes for the ith set of parentheses in the match string. For example,

regexprep ("Bill Dunn", '(\w+) (\w+)', '$2, $1')

returns "Dunn, Bill"

Options in addition to those of regexp are

once

Replace only the first occurrence of pat in the result.

warnings

This option is present for compatibility but is ignored.

Implementation Note: For compatibility with MATLAB, escape sequences in pat (e.g., "\n" => newline) are expanded even when pat has been defined with single quotes. To disable expansion use a second backslash before the escape sequence (e.g., "\\n") or use the regexptranslate function.

See also: regexp, regexpi, strrep.

Package: octave