No law stating that the carpet has to be replaced. Also, you moved in the apartment in an "as is" lease. Unless it is unhealthy (mold and/or mildew), it is not likely that the landlord will replace it. If you move, make sure that the carpet is new in the apartment. If not, ask ifor t to be replaced. If they will not replace it before you move in, then find another apartment.
It's kinda like this. If the carpet was in bad condition when you moved in, then you should have asked to have it replaced before you moved it. Since you did not, then you do not have a right to now. It did not bother you two years ago. If it has gotten worse over the past two years it is due to your neglect. :shrug: