william
05/18/2020, 4:23 PMval a = Regex("foo")
a.replace("foobar", "\\w")
res3: kotlin.String = wbar
i would expect this to return \\wbar
- am I missing something here? Isn't \\
an escape for the \
?william
05/18/2020, 4:27 PMnkiesel
05/19/2020, 6:51 AM\\
with a single \
and `\ is special in replacements to quote e.g. the $
which normally indicates a back reference. So if you welly want \\bwbar
then you have to use either Regex("foo").replace("foobar", "\\\\\\\\w")
or Regex("foo").replace("foobar", """\\\\w""")
(which sidesteps the Kotlin String part)