shell bash add tag
prabhjot drake
`${string/substring/replacement}` replaces *first* match of `substring` with `replacement`. 

How can I replace *last* match of `substring` with `replacement`?
Top Answer
Jack Douglas
Inspired by [this answer on](, you can sandwich the replacement text between the leading and trailing parts:

::: tio S0oszvj/v7ikyDYxKdnRydnQyBjCUFDgSk3OyFdQUqkGyqoCBbVqKyqrwDxlZS0gv1bp/38A
§§§ bash bash
echo "${str%abc*}xyz${str##*abc}"
``` none

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.