replace

Replaces all occurrences of the given regular expression regex in this char sequence with the specified replacement expression.

inline fun CharSequence.replace(regex: Regex, replacement: String): String(source)
val input = "Hello 123 world 456"
val regex = "\\d+".toRegex()
val output = input.replace(regex, "#")
println(output)  // prints: Hello # world #

Source