hi Barjon
Its not illegal!!
If you are married a simple solution is to "bed and spouse" Sell from one partner's account and buy back in the name of the other.
If you are not married, 30 days is the time interval before the new purchase is not tied to the previous sale.
The other trick I do is to have share ISAs for quick in and out deals where capital gains tax is not applicable.
regards