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.
- newpat
- New pattern to replace in s.
- '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.
Outputs
- R
- Type: string | cell
Examples
R = strrep('Replaace the extraa a', 'aa', 'a')
R = Replace the extra a
R = strrep({'Replaace', 'the extraa a'}, 'aa', 'a')
R =
{
[1,1] Replace
[1,2] the extra a
}
R = strrep('Replaaaace the extraaa aaa', 'aa', 'a', 'overlaps', true)
R = Replaaace the extraa aa
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.