How does gas for a nebulae constantly keep getting replenished?
Actually gas for a nebula isn't constantly replenished.
Nebulae can acquire additional material by gravitational attraction from the interstellar medium. Such material is very sparse and can only account for small amounts of mass.
Nebulae however are being created from the debris of supernova explosions of large stars. This process can't continue indefinitely as there will come a time when there is not sufficient material in any nebula to create a large enough star.