In this article, I’m going to show you how to stripping HTML tags out from a string in Swift.
I have a string with HTML tag as below.
let text = "Here is exsample text with html <a href='https://odenza.medium.com'>Click here to visit our contents</a>"
Then, I want to strip html tag by using replacingOccurrences
and create a string extension.
extension String {
var stripHTML: String {
return self.replacingOccurrences(of: "<[^>]+>", with: "", options: .regularExpression)
}
}
Here is result.
print(text.stripHTML)
// result: Here is exsample text with html Click here to visit our contents