regexprep
Returns the result after replacing the regular expression, pat with rep in the input, src.
Syntax
R = regexprep(src, pat, rep)
R = regexprep(src, pat, rep, options...)
Inputs
- src
- Type: string | cell
- pattern
- Type: string | cell
- rep
- Type: string | cell
- options (optional)
- Arguments specifying the search/replace pattern. Valid options are:
- once
- Replaces only the first occurrence of the matching pattern.
- ignorecase
- Ignores the case of the matching pattern.
- emptymatch
- Matches empty sequences.
Outputs
- R
- Type: string
Examples
R = regexprep ('www123.com', '(1)', '.$1')
R = www.123.com
R = regexprep ('1(a)3[A]5-6{7}', '[^A-Z0-9_]', ':', 'ignorecase')
R = 1:a:3:A:5:6:7:
R = regexprep ('1(a)3[A]5-6{7}', '[^A-Z0-9_]', ':', 'ignorecase', 'once')
1:a)3[A]5-6{7}
R = regexprep ({'123', '312'}, {'3', '2'}, {'xy', 'abc'})
R =
{
[1,1] 1abcxy
[2,1] xy1abc
}