Skip to content

Instantly share code, notes, and snippets.

@johnnygoodman
Created August 1, 2010 19:44
Show Gist options
  • Save johnnygoodman/503682 to your computer and use it in GitHub Desktop.
Save johnnygoodman/503682 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'differ'
# Question: Is there a way to say match 1 or more instances of a defined subsequence/grouping?
original = "Epic lolcat fail bellmead drive!"
current = "Epic wolfman fail bellmead dr!"
diff = Differ.diff_by_word(current, original).to_s
puts diff # => "Epic {"lolcat" >> "wolfman"} fail bellmead {"drive" >> "dr"}!
diff =~ /(\{"[a-zA-Z0-9]*" >> "[a-zA-Z0-9s]*"\})/
puts "#{$1} to #{$2} #{$3} to #{$4}"
# => lolcat to wolfman to
# Desired output: lolcat to wolfman to drive to dr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment