Last active
December 14, 2015 16:38
-
-
Save universal/5116185 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
s_full = "South" | |
tests = [ | |
["Some text with S", "S", "South", "Some text with South"], | |
["Some text with S/wrong", "S/wrong", "Something wrong", "Some text with Something wrong"], | |
["Some text with S/wrong", "S", "South", "Some text with S/wrong"] | |
] | |
def match(where, what, replace) | |
where.gsub(/\b#{Regexp.quote(what)}(\s|\z|$)/, replace + '\1') | |
end | |
tests.each do |where, what, replace, expected| | |
replaced = match(where, what, replace) | |
if replaced == expected | |
puts "matched!" | |
else | |
puts "not matching: - #{where} - #{what} - #{replace}" | |
puts "#{replaced} - #{expected}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment