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

Using Gsub With Blocks To Strip Attributes From HTML Tags

DZone's Guide to

Using Gsub With Blocks To Strip Attributes From HTML Tags

·
Free Resource
originally post here:
http://henrik.nyh.se/2007/03/03/using-gsub-with-blocks-to-strip-attributes-from-html-tags/

html = 'Getting rid of id attributes, but not in text: id="not this".' 

html.gsub(/<(.*?)>/) {|innards| innards.gsub(/ id=("|').*?\1/, '') }

# => Getting rid of id attributes, but not in text: id="not this".
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 }}