I'm using Coldfusion.
The following syntax seems to remove all HTML tags for the str
variable:
ReReplaceNoCase(#str#,"<[^>]*(?:>|$)","","ALL")>
However, I'd like to keep both <div>
and </div>
intact. How can I do that?
I'm using Coldfusion.
The following syntax seems to remove all HTML tags for the str
variable:
ReReplaceNoCase(#str#,"<[^>]*(?:>|$)","","ALL")>
However, I'd like to keep both <div>
and </div>
intact. How can I do that?
Instead of a regex, I would recommend using JSoup. It makes parsing and manipulating html fragments much easier.
Download and install JSoup. Create a Whitelist with the tags you wish to keep. Then scrub your html string with JSoup.clean(...):
jsoup = createObject("java", "org.jsoup.Jsoup");
whiteList = createObject("java", "org.jsoup.safety.Whitelist");
cleanString = jsoup.clean( yourHTMLString, Whitelist.none().addTags( [ "div" ] ));
writeDump( cleanString );