If you're really struggling with AS you might find it difficult to get into a regular exercise because of excessive pain and stiffness, particularly during a flare.
It's essential that you don't give up. Even a small amount of exercise will help, and in the long run (even if it doesn't feel like it right away) exercise has been shown time and time again to reduce pain and stiffness in AS if it is done regularly and carefully.
To help kick-start you into an exercise routine, ask your healthcare professionals who are looking after you (such as your rheumatologist) if you can get access to hydrotherapy.
Hydrotherapy typically involves a short session in a small, purpose-built pool with a physiotherapist. The water is much warmer than a swimming pool (more like a warm bath) which helps improve your comfort and range of movement significantly, and there are usually plenty of steps, handrails and hoists to help people in and out of the pool easily regardless of how stiff or immobile you are. You will do a series of stretches and exercises tailored for you, your condition, age and fitness, possibly using floats to support you.
Most people with AS report significant benefit from a course of hydrotherapy, increasing movement, reducing stiffness, and this can be used as a spring-board to get you doing more exercise on a regular basis, like swimming or stretching at home.
Unfortunately, hydrotherapy is often under-funded and difficult to access, so be prepared to persist with your doctor, explain clearly how much pain and stiffness you feel, how much it is limiting you physically and how important it is for you to exercise for long term management of AS. If this fails, look out for any hydrotherapy pools in your local area, some may also be able to offer you sessions privately.