Skip to content

Instantly share code, notes, and snippets.

@Achillefs
Created December 3, 2012 23:56
Show Gist options
  • Save Achillefs/4199201 to your computer and use it in GitHub Desktop.
Save Achillefs/4199201 to your computer and use it in GitHub Desktop.
Lightweight html extraction
class String
def links
self.scan /<a href\=\"[^"]*\"[^>]*>[^<]*<\/a>/
end
def images
self.scan /<img src\=\"[^"]*\"[^>]*>/
end
end
c = %[<p><img src="humbucker.png" />is a type of electric guitar pickup that uses two coils.
<a href="http://google.com/?q=humbucker" class="awesome">Humbuckers</a> get their name from their canceling out interference (they "buck the hum") induced by alternating current sources normally experienced with single coil pickups.
You can contact us at <a href="mailto:wha@humbuckercode.co.uk">our email, yo</a><br/><img src="humbucker2.png" id="moar"></p>]
puts c.links
puts c.images
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment