Skip to content

Instantly share code, notes, and snippets.

@universal
Last active December 14, 2015 16:38
Show Gist options
  • Save universal/5116185 to your computer and use it in GitHub Desktop.
Save universal/5116185 to your computer and use it in GitHub Desktop.
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