# xarray.DataArray.str.replace

#### DataArray.str.replace(pat, repl, n=-1, case=None, flags=0, regex=True)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/accessor_str.py#L1893-L1966)

Replace occurrences of pattern/regex in the array with some string.

If pat, repl, or ‘n\` is array-like, they are broadcast
against the array and applied elementwise.

* **Parameters:**
  * **pat** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str) or [`re.Pattern`](https://docs.python.org/3/library/re.html#re.Pattern) or [array-like](https://numpy.org/doc/stable/glossary.html#term-array_like) of [`str`](https://docs.python.org/3/builtins/stdtypes.html#str) or [`re.Pattern`](https://docs.python.org/3/library/re.html#re.Pattern)) – String can be a character sequence or regular expression.
    If array-like, it is broadcast.
  * **repl** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str) or [`callable()`](https://docs.python.org/3/builtins/functions.html#callable) or [array-like](https://numpy.org/doc/stable/glossary.html#term-array_like) of [`str`](https://docs.python.org/3/builtins/stdtypes.html#str) or [`callable()`](https://docs.python.org/3/builtins/functions.html#callable)) – Replacement string or a callable. The callable is passed the regex
    match object and must return a replacement string to be used.
    See [`re.sub()`](https://docs.python.org/3/library/re.html#re.sub).
    If array-like, it is broadcast.
  * **n** ([`int`](https://docs.python.org/3/builtins/functions.html#int) or [array](https://numpy.org/doc/stable/glossary.html#term-array) of [`int`](https://docs.python.org/3/builtins/functions.html#int), *default*: `-1`) – Number of replacements to make from start. Use `-1` to replace all.
    If array-like, it is broadcast.
  * **case** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default*: [`True`](https://docs.python.org/3/builtins/constants.html#True)) – If True, case sensitive.
    Cannot be set if pat is a compiled regex.
    Equivalent to setting the re.IGNORECASE flag.
  * **flags** ([`int`](https://docs.python.org/3/builtins/functions.html#int), *default*: `0`) – Flags to pass through to the re module, e.g. re.IGNORECASE.
    see [compilation-flags](https://docs.python.org/3/howto/regex.html#compilation-flags).
    `0` means no flags. Flags can be combined with the bitwise or operator `|`.
    Cannot be set if pat is a compiled regex.
  * **regex** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default*: [`True`](https://docs.python.org/3/builtins/constants.html#True)) – 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.
