From: botp Date: 2012-07-15T19:27:54+09:00 Subject: Re: What is done by Ruby On Sat, Jul 14, 2012 at 11:14 PM, jacbs loaru wrote: >> i have a list of domains and i want to apply acl such as ".example.com" will >> match all domains that starts with "example.com". >> but the problem is that domain start in a reverse order. >> i was thinking on what is the best\better way to match a domain to domain >> list ? just reverse them before comparing or you can use regex to compare relative to end of string.. eg > s=%w(one.example.com two.testing.com three.four.example.com) => ["one.example.com", "two.testing.com", "three.four.example.com"] >s.each do |x| p [x,x.reverse.start_with?(d.reverse),x=~/#{d}$/] end ["one.example.com", true, 4] ["two.testing.com", false, nil] ["three.four.example.com", true, 11] kind regards -botp