require 'rubygems'
require 'differ'
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
views:
34answers:
1
+1
A:
I don't know 'differ', but how about:
require 'rubygems'
require 'differ'
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"}!
captures = diff.scan /\{"([a-zA-Z0-9]*)" >> "([a-zA-Z0-9s]*)"\}/
captures.each {|c| puts "#{c[0]} to #{c[1]}" }
Adrian
2010-08-01 19:59:06
Um...scan passes an array back doesn't it. Yes indeed it does. Thanks Adrian.
johnnygoodman
2010-08-03 03:59:38