Ruby – replace the first occurrence of a substring with another string February 25, 2023 by Tarik Use #sub: a.sub('bar', "BAR")