Skip to content

Instantly share code, notes, and snippets.

@johnnygoodman
Created August 1, 2010 22:04
Show Gist options
  • Save johnnygoodman/503815 to your computer and use it in GitHub Desktop.
Save johnnygoodman/503815 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'differ'
# There could be only one match
original = "Epic lolcat fail bellmead drive!"
current = "Epic wolfman fail bellmead dr!"
diff = Differ.diff_by_word(current, original).to_s
# => "Epic {"lolcat" >> "wolfman"} fail bellmead {"drive" >> "dr"}!
diff =~ /(\{"[a-zA-Z0-9]*" >> "[a-zA-Z0-9s]*"\})/ # => This will match the one instance
# There could be two matches, or 2+ matches
original = "Same Same diff Same Same diff Same Same diff"
current = "Same Same wooo Same Same wooo Same Same wooo"
# => "Same Same {"diff" >> "wooo"} Same Same {"diff" >> "wooo"} Same Same {"diff" >> "wooo"}"
#diff =~ /\{"(\w+)" >> "(\w+)"\}.+\{"(\w+)" >> "(\w+)"\}/ # => This will match two instances
# How can I write a regexp that'll match one string for N instances of the pattern {"foo" >> "bar"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment