https://kotlinlang.org logo
#android
Title
# android
k

KotlinLeaner

08/03/2022, 3:15 PM
Hello, I have string
val string = "Welcome<br>how are you?"
when I am trying to regex
Copy code
string?.replace("\\<.*?\\>", " ");
it's not working. It returning same string. Anyone know how to fix this problem?
c

Chrimaeon

08/03/2022, 3:30 PM
you are missing a
toRegex()
Copy code
string.replace("\\<.*?\\>".toRegex(), " ")
your implementation is just a string replacement.
and if you use the
"""
multiline string. you can omit the escape characters.
Copy code
string.replace("""<.*?>""".toRegex(), " ")
k

KotlinLeaner

08/03/2022, 3:34 PM
ohh nice thank you
r

Robert Williams

08/03/2022, 4:56 PM
Since you’re asking in #android maybe a better solution to what you’re actually trying to do is https://developer.android.com/reference/android/text/Html#fromHtml(java.lang.String) ?
3 Views