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

Snippets has posted 5883 posts at DZone. View Full User Profile

Using Gsub With Blocks To Strip Attributes From HTML Tags

  • submit to reddit
        originally post here:
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 
 attributes, but not in text: id="not this".