Edit: Reed the ffing description before downvoting!
I have been trying to find a solution for days. I found several posts here on stackoverflow but none of them that handle a similiar solution. In receive a description text for an object from the backend in html like this:
"My two favorite places to indulge on my sugar cravings are <a
href=\"https://huizevanwely.nl/\">Huize van Wely</a> (located in the
Gelderlandplein shopping mall and Beethovenstraat) and <a
href=\"http://linnick.nl/\">Linnick</a>. The first is one I ........."
I would like to find a way to detect the links and only show the link text ánd have the link text clickable.
I have this method that sucessfully strips the links:
func stripLinks(text: String) -> String {
let pattern = "<a href=\"[^\"]+\">([^<]+)</a>"
do {
let regex = try NSRegularExpression(pattern: pattern,
options: [])
let stripped = regex.stringByReplacingMatches(in: text,
options: [],
range: NSRange(location: 0, length: text.count),
withTemplate: "$1")
return stripped
} catch {
print("WARNING: regex failed")
return text
}
}
But this way the textView does not detect the links anymore, so i have the plain text but you can't click the text to go to the website.
Can anyone help with an approach that would work, please. I think that i should use an attributed string to get this working but i have failed in trying to implement it.
Thanks in advance.