Well usually lost height can be explained by being "hunched". It's probably possible that you lost a few centimeters if your vertebraes are a bit more "compressed" than they used to be or if you had bone loss of some form. An x-ray would tell you more.

Doing proper stretching exercices and watching your posture can definitely help you keep your height for a longer time. Not all people with AS lose height, but it can be one consequence.

As far as regaining your height, it really depends on what has caused the loss in the first place.