Take that, regulators.

With questions swirling whether its combination would get approved by regulators, Walgreens Boots Alliance (WBA) and Rite-Aid (RAD) struck a clever deal on Thursday. Walgreens will pay $5.175 billion to Rite-Aid in cash and receive 2,186 stores in return. Walgreens will also pay Rite-Aid a $325 million termination fee for its planned buyout of the company.

Walgreens will be an even bigger drug-selling beast, with more than 15,000 stores spanning 11 countries. As for Rite-Aid, it will be left with about 2,300 stores once the deal closes in six months.

"I view this deal as being more attractive...the deal is expected to give us significant benefits," said Stefano Pessina, Walgreens Boots Alliance executive vice chairman and CEO, on an earnings call with analysts.

Pessina said, after "detailed discussions with Rite Aid," both parties agreed that the merger would likely not pass with regulators, so they struck the new deal.

"Where there is a will, there is a way," Pessina said on the call, adding that for Walgreens, the "change brings opportunity" for new partnerships.

While largely overshadowed by its merger termination, Walgreens Boots Alliance did report third-quarter earnings this morning, too. The company posted earnings of $1.33 a share on revenue of $30.1 billion, beating Wall Street's estimates for earnings of $1.30 a share on revenue of $29.7 billion.

Shares of Walgreens rose 0.3% to $77.35 early Thursday afternoon. Rite-Aid dropped 28% to $2.85.

Fred's (FRED) stock crashed 19% to $9.97 as it will be shut out of buying 865 stores the combined company planned to divest.

"While the acquisition of additional stores was an opportunity for growth, we always viewed it as a potential outcome that would accelerate our transformation, not define it," Fred's CEO Michael Bloom said. "This is a disappointing outcome; however, the termination of the transaction has no impact on the Company's transformation strategy or our ability to execute."

Walgreens Boots Alliance is a holding in Jim Cramer's Action Alerts PLUS Charitable Trust Portfolio. Want to be alerted before Cramer buys or sells WBA? Learn more now.

Visit here for the latest business headlines.

Read More Trending Articles:

More from Stocks

Pegasystems Founder Explains Why He Has One of the Hottest Tech Stocks Around

Pegasystems Founder Explains Why He Has One of the Hottest Tech Stocks Around

9 Stocks Goldman Sachs Thinks Will Blow Wall Street's Performance Away in 2019

9 Stocks Goldman Sachs Thinks Will Blow Wall Street's Performance Away in 2019

Jim Cramer on U.S.-China Trade: The Media Has it Wrong

Jim Cramer on U.S.-China Trade: The Media Has it Wrong

Is Tesla's Stock Set to Nearly Double to $500?

Is Tesla's Stock Set to Nearly Double to $500?

Tesla's $78,000 Model 3 Is a Bargain. Here's Why

Tesla's $78,000 Model 3 Is a Bargain. Here's Why