US pharmacy chain Walgreens announced a new deal on Thursday to buy half of competitor Rite Aid's stores for nearly $5.2 billion after canceling a two previous merger attempts.

The Walgreens Boots Alliance announced merger plans with Rite Aid Corporation in October 2015 and revised the in January with a plan for Rite Aid to sell some of its stores to Fred's, Inc—a third pharmacy chain—but the plans continued to face opposition from .

Under the new deal, Walgreens will purchase 2,186 stores and three distribution centers from Rite Aid.

Like the frustrated merger deals, the purchase is subject to approval by regulators.

"We believe this new transaction addresses competitive concerns previously raised with respect to the prior transaction," Walgreens CEO Stefano Pessina said in a statement .

"This new transaction extends our growth strategy and offers additional operational and financial benefits. It will allow us to expand and optimize our retail pharmacy network in key markets in the US, including the Northeast."