Is there way to replace n occurrences starting from the end of a string?

Another option, more concise and efficient than the previous:

julia> join(rsplit(foo, "buzz", limit=3), "baz")
"fizz_buzz_fizz_buzz_fizz_buzz_fizz_baz_fizz_baz"

According to the documentation, this solution should also support regexes, but the code for that seems to be missing.

1 Like