A yeshiva was collecting money for a megila, I donated a sum and 2 hours later a donor walked in and donated the whole thing. Am I allowed to take back the money?
Answer:
You do not have a right to take back the money.
Sources:
The Gemara writes that "leftover money" is used for the same type of purpose as the donation was given for (see Shulchan Aruch 253:6).
Although the money was given for a specific purpose, it was given to the yeshiva, and the yeshiva will have the right to use it for other purposes.
Best wishes.