re = /[A-Z]{3}( to |-)[A-Z]{3}/m
str = 'I recently traveled YWG-LHR and returned home from EDI to YWG with AC Rouge. I must say I was pleasantly surprised with how well the trip went in both directions, but I\'m glad I didn\'t have to transit in ORD.'
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html