Can I replace it with ANY 12 volt battery of comparable size?
No.
In the first instance, is it a rechargeable or non-rechargeable battery? -- you can't swap really swap them. Rechargeable batteries come in a number of different kinds which have different charging circuits and properties. You can't use a battery of one type where the charging circuit is for another. The main kinds of rechargable batteries are Lead-Acid, Nickel-Cadmium, and Lithium-Ion, but there really are many other kinds. Batteries are high-density stores of energy, and if you abuse them you can get sudden release of that energy, ie explosions, fires etc. It's really worth reading Why is there so much fear surrounding LiPo batteries? and watching the linked videos.
Second, do you know anything about the device that's being powered? The usage patterns (discharge frequency and low/high current) are different for different devices, and correspondingly battery selection has to match.
But yes
If you get a battery of the right technology with the same charging requirements with similar capacity and it fits in the box or you can get it connected somehow ... then it will work. It's the charging requirements which are the problem, if you don't have any specification for the battery.
PS. You say in comments its for a microscope. If it's just for the lamp any modifications are likely to be much more successful than if it's for some other feature of a complex microscope, but we can't really guess what those might be unless you tell us about the device: a photo or two would really go a long way!