Method: Polars::StringNameSpace#replace

Defined in:
lib/polars/string_name_space.rb

#replace(pattern, value, literal: false, n: 1) ⇒ Series

Replace first matching regex/literal substring with a new string value.

Examples:

s = Polars::Series.new(["123abc", "abc456"])
s.str.replace('abc\b', "ABC")
# =>
# shape: (2,)
# Series: '' [str]
# [
#         "123ABC"
#         "abc456"
# ]

Parameters:

  • pattern (String)

    A valid regex pattern.

  • value (String)

    Substring to replace.

  • literal (Boolean) (defaults to: false)

    Treat pattern as a literal string.

  • n (Integer) (defaults to: 1)

    Number of matches to replace.

Returns:



773
774
775
# File 'lib/polars/string_name_space.rb', line 773

def replace(pattern, value, literal: false, n: 1)
  super
end