Never been to DZone Snippets before?

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 (See related posts)

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

You need to create an account or log in to post comments to this site.


Click here to browse all 5140 code snippets

Related Posts