Well just think of it like this. A company’s share price is just based on the value of the company, more specifically how investors value the company as they’re the ones who choose how much to buy and sell the share for. But as soon as the company pays out say £0.10 on a £5 share, the company no longer has that cash, so now the company is worth £0.10 less per share. Basically it doesn’t matter when you buy a share, because that £0.10 will be there somewhere in theory, whether that be in cash in your hand or in the value of your shares.
Basically in theory you could buy the £5 share before the ex date and get 10p to buy you an extra 0.02 shares in the company, or you could buy it on the ex and buy 1.02 shares for £5. Both will arrive at the same outcome. Sorry for waffling but I hope it helps.