Severe, sudden, lancinating pains in the rectal area due to rectal spasm or sudden strong muscle contractions that come and go, are symptom of IBS.
IBS symptoms tend to get worse during menstrual period and stress.
Actually, there are two functional anorectal pain syndromes: Proctalgia fugax (occurring due to spasm of the anal sphincter) and Levator ani syndrome (spasms of the pelvic floor muscles).
They may be associated with irritable bowel syndrome, and both Proctalgia fugax and Levator ani syndrome, may co-exist.
You may get some medications or tips from your physician how to ease the pain, but, in most of the cases the pain can't be avoided.
Best wishes!
Marija