strrep

Searches and replaces all instances of the pattern pat in s with the new pattern newpat. The output R will be a string or a cell of strings, based on the type of s.

Syntax

R = strrep(s, pat, newpat)

R = strrep(s, pat, newpat, 'overlaps', value)

Inputs

s
Type: string | cell
pat
Pattern to search for in s.
Type: string
newpat
New pattern to replace in s.
Type: string
'overlaps', value (optional)
Name-value pair for manipulating the output R. Valid options for value are true or false. A value of true will replace every instance of pat while a value of false will replace only unique instances of pat.
Type: logical

Outputs

R
Type: string | cell

Examples

String input:
R = strrep('Replaace the extraa a', 'aa', 'a')
R = Replace the extra a
Cell array input:
R = strrep({'Replaace', 'the extraa a'}, 'aa', 'a')
R =
{
[1,1] Replace
[1,2] the extra a
}
String input with overlapstrue:
R = strrep('Replaaaace the extraaa aaa', 'aa', 'a', 'overlaps', true)
R = Replaaace the extraa aa
String input with overlaps false:
R = strrep('Replaaaace the extraaa aaa', 'aa', 'a', 'overlaps', false)
R = Replace the extra a

Comments

An optional name-value pair, overlaps, value, can be used to specify R. Valid values of value are true or false. A value of true replaces pat with newpat in every matching instance of s, while a value of false will replace only unique instances.