Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

String#sub!

str.sub!(pattern, replacement) → str or nil
str.sub!(pattern) {|match| block } → str or nil

Performs the same substitution as String#sub in-place.

Returns str if a substitution was performed or nil if no substitution was performed.

See also #sub #succ #strip! #succ! also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1