Kaley Cuoco-Sweeting got lucky when she married Ryan Sweeting.

"The Big Bang Theory" actress used to be in a long-term relationship with her co-star on the CBS comedy, Johnny Galecki. During her appearance on Andy Cohen's "Whatch What Happened Live," Cuoco-Sweeting opened up about her relationship with Galecki and his relationship with her husband, Ryan Sweeting.

"Well, we dated like five years ago, so I think we both moved on. Johnny is actually one of my best friends. It's a situation that ended well," Cuoco-Sweeting told Cohen. "I understand sometimes it doesn't. It could have gone horrible."

"He's one of my dearest friends. Ryan loves him. Johnny loves him. It's been a long time, so it's great," she continued. "I got lucky! That could have been horrible."

Cuoco-Sweeting, 29, and Galecki, 40, met on the set of "The Big Bang Theory" and dated in secret for three years from 2007-2010, according to US weekly. In December 2013, Cuoco-Sweeting married professional tennis player Sweeting in a fire-and-ice themed wedding.

Cuoco-Sweeting ranked atop Forbes list of the highest-paid TV actresses in 2015 along with "Modern Family" star Sofia Vergara. The pair both took in an impressive $28.5 million last year.

Cuoco-Sweeting and her co-stars Galecki and Jim Parsons all negotiated a salary of $1 million per episode for "The Big Bang Theory."