Hello, I have string `val string = "Welcome<br&...
# android
k
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
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
ohh nice thank you
r
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) ?