Take that, regulators.

With questions swirling whether its combination would get approved by regulators, Walgreens Boots Alliance (WBA) - Get Report and Rite-Aid (RAD) - Get Reportstruck 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:

  • Nike Officially Arrives on Amazon, but Then Adidas' Stock Does Something Bizarre
  • Elon Musk Teases 'News' on Tesla's Highly Anticipated Model 3
  • Big Banks Are on Steroids: Market Recon
  • Investing With Intent: Cramer's 'Mad Money' Recap (Thursday 6/29/17)
  • Here's Why Amazon Could Feast on the Remaining Carcass of Rite Aid After Failed Walgreens Merger