Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Html Stripping

DZone's Guide to

Html Stripping

·
Free Resource
Stripping html tags, with an optional array of tags to be preserved.


	def strip_html(str, allow = ['a','img','p','br','i','b','u','ul','li'])
		str = str.strip || ''
		allow_arr = allow.join('|') << '|\/'
		str.gsub(/<(\/|\s)*[^(#{allow_arr})][^>]*>/,'')
	end
Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}