Logo

Programming-Idioms

History of Idiom 296 > diff from v15 to v16

Edit summary for version 16 by steenslag:
New Ruby implementation by user [steenslag]

Version 15

2022-03-29, 20:43:00

Version 16

2022-06-14, 19:02:31

Idiom #296 Replace last occurrence of substring

Assign to x2 the value of string x with the last occurrence of y replaced by z.
If y is not contained in x, then x2 has the same value as x.

Idiom #296 Replace last occurrence of substring

Assign to x2 the value of string x with the last occurrence of y replaced by z.
If y is not contained in x, then x2 has the same value as x.

Variables
x2,x,y,z
Variables
x2,x,y,z
Extra Keywords
substring substitute
Extra Keywords
substring substitute
Code
x2 = x.gsub(/#{y}(?!.*#{y})/, z )
Comments bubble
Regex with negative lookahead.