DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Using Gsub With Blocks To Strip Attributes From HTML Tags
originally post here:
http://henrik.nyh.se/2007/03/03/using-gsub-with-blocks-to-strip-attributes-from-html-tags/
html = 'Getting <a href="#" id="foo">rid</a> of <code id="bar">id
attributes, but not in text: id="not this".'
html.gsub(/<(.*?)>/) {|innards| innards.gsub(/ id=("|').*?\1/, '') }
# => Getting <a href="#">rid</a> of id
attributes, but not in text: id="not this".





