Created
August 1, 2010 22:04
-
-
Save johnnygoodman/503815 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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