If you buy an secondhand mainsail you should change the sail numbers on it to match the sail number of your boat. In the same way, if you buy a boat abroad you should change the national letters so they are correct, for example change "IRL" to "GBR". The old numbers or letters should pull off OK, they might leave some glue behind. It's best to be careful, and try minimise the amount of glue left behind. Pulling the number off gently, and at 180 degrees to the bit of number still stuck on (so the pulled off bit of number is over the remaining stuck on section) can help. You could also try encouraging any glue sticking to the sail at the boundary where the number is coming off, to stick to the number instead by scraping it with a knife or similar. Any remaining glue/gunk can be removed with acetone. I also find Brasso metal polish also very good for removing sticky gunk. I think the amount of exposure to UV light has a big affect on how much glue is left behind. Changing the numbers on a ten year old mainsail that had only been used at a couple of events was easy, no glue left behind. But on a similar sail that had done a lot more events, there was a lot of glue and it was a bit of a pig to get off. However, getting the old glue off is worth it as it looks much better you don't have sticky patches left behind which will collect all manner of dirt, grass clippings, dust,.....
You can buy new letters or numbers (must be black) from any good chandler (e.g. Pinnell & Bax) or you local sailmaker will sell you some, or you can buy a small amount of black sticky backed polyester from a local sailmaker and make your own (cheaper). If you make your own you can use the numbers or letters on another sail as a pattern. Don't forget to turn the pattern over, so you mark out the back of the pattern onto the paper on the back of the roll of sticky backed cloth.
Don't forget that the insignia goes above the national letters which go above the sail numbers. Don't place national letters or sail numbers "back to back", they need to go in separate rows with those on the starboard side of the sail uppermost. Insignias can only be placed "back to back" if the starboard side one is "reversed" so the "points" are towards the leech.
Numbers and letters have to be a minimum height of 230mm (most are a lot bigger), a minimum of 45mm apart and a minimum of 45mm from the edge of the sail to comply with the Racing Rules of Sailing (RRS) Appendix G. Please note that 'digital' font (where numbers are made up from straight line elements in fixed locations in a similar way to an liquid crystal display) are not permitted.