Skip to content

Instantly share code, notes, and snippets.

@yelvert
Created April 22, 2012 00:33
Show Gist options
  • Save yelvert/2440523 to your computer and use it in GitHub Desktop.
Save yelvert/2440523 to your computer and use it in GitHub Desktop.
tweet = "What a great night, awesome drinks. :-)"
punctuation_regex = Regexp.new('([^\w\d\s]+)')
tweet.gsub!(punctuation_regex, ' \1 ')
tokens = tweet.split
tokens.compact!
tokens.each do |token|
is_punctuation = !!(token =~ punctuation_regex)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment