Remove all HTML tags like
or <p>
from string. I used below code but it's not working.
var content = "<p> test result</p><br/>"; // My String
content.replacingOccurrences(of: "<[^>]+>", with: "", options: String.CompareOptions.regularExpression, range: nil)
but it does not remove all HTML tags from string.
Select the HTML element which need to remove. Use JavaScript remove() and removeChild() method to remove the element from the HTML document.
//remove html tags from a string, leaving only the inner text function removeHTML(str){ var tmp = document. createElement("DIV"); tmp. innerHTML = str; return tmp. textContent || tmp.
The strip_tags() function strips a string from HTML, XML, and PHP tags. Note: HTML comments are always stripped.
var content = "<p> test result</p><br/>"; // My String
let a = content.replacingOccurrences(of: "<[^>]+>", with: "", options: String.CompareOptions.regularExpression, range: nil)
a will be: test result
let b = a.replacingOccurrences(of: "&[^;]+;", with: "", options: String.CompareOptions.regularExpression, range: nil)
b will now be: test result
This will also take care of <
and so on. There is no magic. Find out what you need and then write the proper RegEx.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With