Xanax and flexeril belong to two different drug classes. Doctors usually prescribe flexeril to relax the muscle contractions that cause pain resulting from muscle strains, sprains, injuries or muscle spasms. However, Xanax is a sedative that is often prescribed to help patients treat anxiety. Talk to your doctor about which one would be better to relax you.