A Regular Expression to Generate Dash Separated Slugs AKA Pretty URLs
This regular expression matches non alphanumeric characters in a string. r = /[^a-z0-9]{1,}/i You can use it to create URL friendly slugs. slug = "hello world!".gsub(/[^a-z0-9]{1,}/i, '-').downcase # => hello-world In combination wit...
Written by Sean Behan on 08/22/2013
How to Extract the Title From an HTML Page with Ruby
This snippet will make a request to this page and extract the title from the title tag. require 'open-uri' html = open('http://www.seanbehan.com/how-to-extract-the-title-from-an-html-page-with-ruby').read title = html.match(/(.*)/) { $1 } pu...
Written by Sean Behan on 08/22/2013
Email Obfuscation and Extraction from Text with Rails
There is a helper method for handling the obfuscation of email addresses in Rails. mail_to "me@domain.com", "My email", :encode => "hex" # => My email If you want to then extract an email address(or all email addresses) from a block of text here is the...
Written by Sean Behan on 06/17/2012