Hey I want to filter link from string in kotlin wa...
# android
v
Hey I want to filter link from string in kotlin way. For example
Copy code
val string = "Check out this property I found using Daft 
    
    https://www.daft.ie"
Output
Copy code
https://www.daft.ie
e
if it's for display then Linkify else Patterns.WEB_URL or your own regex
👍 1
v
@ephemient can you please give me example I can't understand that sorry 😞
👍 1
z
You can use regular expression to extract the link or some other tricks such as splitting the text and getting whichever item contains a link
j
Example using ephemient's suggestion:
Copy code
val inputString = "Check out this property I found using Daft\n\nhttps://www.daft.ie"
        val regex = Patterns.WEB_URL.toRegex()
// If there is matching string, then find method returns non-null MatchResult
        val match = regex.find(inputString)!!
        println(match.value) // https://www.daft.ie
101 Views