Pakistan , a key anti-terrorism ally of the United States , has been trying to flush out foreign militants from the region for almost 18 months .