# 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 (string or compiled regex) – String can be a character sequence or regular expression.
  - repl (string or 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()`.
  - n (int, default -1 (all)) – Number of replacements to make from start
  - case (boolean, default None) –
    - 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 (no flags)) –
    - re module flags, e.g. re.IGNORECASE
    - Cannot be set if pat is a compiled regex
  - regex (boolean, default 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 – A copy of the object with all matching occurrences of pat replaced by repl.
  Return type: | same type as values