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 unix.se](https://unix.stackexchange.com/a/426833), you can sandwich the replacement text between the leading and trailing parts:

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

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.