```val a = Regex("foo") a.replace("foobar", "\\w")...
# announcements
Copy code
val a = Regex("foo")
a.replace("foobar", "\\w")
res3: kotlin.String = wbar
i would expect this to return
- am I missing something here? Isn't
an escape for the
Kotlin strings replace
with a single
and `\ is special in replacements to quote e.g. the
which normally indicates a back reference. So if you welly want
then you have to use either
Regex("foo").replace("foobar", "\\\\\\\\w")
Regex("foo").replace("foobar", """\\\\w""")
(which sidesteps the Kotlin String part)