Record date vs Ex Date

Since the holder-of-record date is generally 2 business days after the ex-dividend date, who exactly receives the dividend? I thought only those who buy before the ex-date would receive the dividend, but if someone buys ON the ex-date, isn’t it plausible that settlement would occur in 2 days and thus the buyer would be listed on the company’s books on the record date, thereby allowing them to buy the share cheap and receiving the dividend?

Think of the ex-dividend date similar to an ex-girlfriend. If it has “ex”, you are no longer with it. The ex-dividend date is the first day the stock trades without the dividend.

That cracked me up