xarray.core.accessor_str.StringAccessor.replace¶
-
StringAccessor.
replace
(pat, repl, n=- 1, case=None, flags=0, regex=True)¶ Replace occurrences of pattern/regex in the array with some string.
- Parameters
pat (
str
orre.Pattern
) – String can be a character sequence or regular expression.repl (
str
orcallable()
) – Replacement string or a callable. The callable is passed the regex match object and must return a replacement string to be used. Seere.sub()
.n (
int
, default:-1
) – Number of replacements to make from start. Use-1
to replace all.-
If True, case sensitive (the default if pat is a string)
Set to False for case insensitive
Cannot be set if pat is a compiled regex
flags (
int
, default:0
) –re module flags, e.g. re.IGNORECASE. Use
0
for no flags.Cannot be set if pat is a compiled regex
-
If True, assumes the passed-in pattern is a regular expression.
If False, treats the pattern as a literal string
Cannot be set to False if pat is a compiled regex or repl is a callable.
- Returns
replaced (
same type as values
) – A copy of the object with all matching occurrences of pat replaced by repl.