thanks in advance i need a bit help to break the ice that my head is in.

i am working on ICAP server and i am building some acls for content 
filtering.

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 ?
i have a sql(PGSQL\MYSQL) db that contains the list of domains.
so i was thinking to use "divide and Conquer way" to dissemble the 
requested domain such as "subporndomain.example.com" to 
["com","example","subporndomain"] and then to fetch from the db all the 
domains that starts with "example.com" and then check match each and one 
of them(if any record exists) to the requested domain.

i was thinking of using the "string".start_with?
method in reverse such as 
"moc.elpmaxe.niamodnropbus".start_with?(["moc.elpmaxe", ...])
with the list of domains as a prefix..
but there is one problem: i cant match all the domains as prefix because 
some of them are not a prefix but an exact match.
so i will need to do some code like this:

dom = "subdomain.example.com"
domacl = ".example.com"
domacl1 = "example.com"

def match?(domacl,dom)
	if domacl.start_with?(".")
	   return  ( dom.reverse.start_with?(domacl.reverse.chop) )	
	else
  	   return true if dom.eql?(domacl)
	   return false
	end
end

 >> match?(domacl,dom)
=> true
 >> match?(domacl1,dom)
=> false


so it works..

my goal is maximum efficiency.

Thanks,
Elizer

-- 
Eliezer Croitoru
https://www1.ngtech.co.il
IT consulting for Nonprofit organizations
eliezer <at> ngtech.co.il